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
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:
./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:
./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:
./input.sh | ./bin/PipelineTest.exe /pipe.Test > ./3.txt
./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!\""]
![Image 1](/KB/dotnet/1119712/Ubuntu.png)
![Image 2](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
This CLI pipeline VisualBasic language programming feature was tested successfully on both Windows10 and Ubuntu.