Click here to Skip to main content
13,802,192 members
Click here to Skip to main content
Add your own
alternative version

Stats

6K views
43 downloads
3 bookmarked
Posted 21 Aug 2016
Licenced CPOL

VisualBasic CLI Pipeline

Rate this:
Please Sign up or sign in to vote.
How to use pipeline feature for linux programming

Introduction

CLI pipeline is the most important language programming feature of the data analysis industry/or server technique as it provides the basics of the analysis workflow automation and language hybrids feature. Almost all of the Linux server tools support this pipeline feature as nearly all of the management automation on the Linux server is based on the bash scripting.

Here is the pipeline API that provided in VisualBasic language server runtime: Microsoft.VisualBasic.CommandLine.CommandLine, and it makes this CLI pipeline more simple.

API Description
OpenStreamInput(String, String) As System.IO.StreamReader Open file input or std_in device as input
OpenStreamOutput(String) As System.IO.StreamWriter Open file output or std_out device as output

Usage Example

CLI

Imports System.IO
Imports Microsoft.VisualBasic.CommandLine
Imports Microsoft.VisualBasic.CommandLine.Reflection
Imports Microsoft.VisualBasic.Serialization.JSON

Module Program

    Public Function Main() As Integer
        Return GetType(Program).RunCLI(App.CommandLine)
    End Function

End Module

input bash

#!/bin/sh
echo "Hello World!!!"
echo "Test success!"

1. Only file supports

<ExportAPI("/file", Usage:="/file /in <file.txt> [/out <out.txt>]")>
Public Function OnlySupportsFile(args As CommandLine) As Integer
    Dim [in] As String = args("/in")
    Dim out As String = args.GetValue("/out", [in].TrimSuffix & ".output.json")
    Return [in].ReadAllLines.GetJson.SaveTo(out).CLICode
End Function

Test bash script:

# file inputs
# read file input as text file and output the processed content as json
./bin/PipelineTest.exe /file /in ./input.sh /out ./1.txt

Test output:

["#!\/bin\/sh","echo \"Hello World!!!\"","echo \"Test success!\""]

2. Only std_in/std_out(Pipeline) supports

<ExportAPI("/std", Usage:="/std <input> <output>")>
Public Function JustStdDevice() As Integer
    Using input = Console.OpenStandardInput, output = New StreamWriter(Console.OpenStandardOutput)
        Call output.Write(New StreamReader(input).ReadToEnd.lTokens.GetJson)
    End Using

    Return 0
End Function

Test bash script:

# std inputs
./input.sh | ./bin/PipelineTest.exe /std > ./2.txt

Test output:

["Hello World!!!","Test success!"]

3. Support both(file/Pipeline)

<ExportAPI("/pipe.Test", _
Usage:="/pipe.Test /in <file.txt/std_in> [/out <out.txt/std_out>]")>
Public Function SupportsBothFileAndPipeline(args As CommandLine) As Integer
    Using out = args.OpenStreamOutput("/out")
        Dim inData As String() = args.OpenStreamInput("/in").ReadToEnd.lTokens
        Call out.Write(inData.GetJson)
    End Using

    Return 0
End Function

Test bash script:

# both supports
# just using standard input/output
./input.sh | ./bin/PipelineTest.exe /pipe.Test > ./3.txt
# using file io
./bin/PipelineTest.exe /pipe.Test /in ./input.sh /out ./4.txt

Test output: 3.txt:

["Hello World!!!","Test success!"]

Test output: 4.txt:

["#!\/bin\/sh","echo \"Hello World!!!\"","echo \"Test success!\""]

This CLI pipeline VisualBasic language programming feature was tested successfully on both Windows10 and Ubuntu.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mr. xieguigang 谢桂纲
Student 中国南方微生物资源利用中心(SMRUCC)
China China
He is good and loves VisualBasic!



github: https://github.com/xieguigang

You may also be interested in...

Comments and Discussions

 
QuestionCool Pin
LauraThomas23-Aug-16 4:41
memberLauraThomas23-Aug-16 4:41 
QuestionGreat Pin
Member 1269737722-Aug-16 5:41
memberMember 1269737722-Aug-16 5:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.181215.1 | Last Updated 22 Aug 2016
Article Copyright 2016 by Mr. xieguigang 谢桂纲
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid