Skip to content
/ Flucli Public

Library for interacting with external command-line interfaces.

License

Notifications You must be signed in to change notification settings

lemutec/Flucli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NuGet GitHub license Actions

Flucli

Library for interacting with external command-line interfaces.

Ported from CliWrap and support .netstandard 2.0 without other dependencies.

Support Verb="runas" and simplify some APIs.

Usage

Command

CliResult result = await "cmd"
    .WithArguments("/c echo Hello World!")
    .ExecuteAsync();

Console.WriteLine("ExitCode is " + result.ExitCode);

Piper

StringBuilder stdout = new();
StringBuilder stderr = new();

var command1 = "cmd"
    .WithArguments("/c echo Hello World!");

var command2 = "cmd"
    .WithArguments("/c findstr o")
    .WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdout, Encoding.UTF8))
    .WithStandardErrorPipe(PipeTarget.ToStringBuilder(stderr, Encoding.UTF8));

CliResult result = await (command1 | command2).ExecuteAsync();

Console.WriteLine("STDOUT: " + stdout.ToString());
Console.WriteLine("STDERR: " + stderr.ToString());
Console.WriteLine("ExitCode is " + result.ExitCode);

Parser

StringBuilder stdout = new();
StringBuilder stderr = new();

Cli command = "cmd /c echo Follow | cmd /c findstr F | cmd /c findstr l*"
    .ParseCli()
    .PipeTail // Switch to tail command
    .WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdout, Encoding.UTF8))
    .WithStandardErrorPipe(PipeTarget.ToStringBuilder(stderr, Encoding.UTF8))
    .PipeHeader; // Switch to header command

CliResult result = await command.ExecutePipeAsync();

Console.WriteLine("STDOUT: " + stdout.ToString());
Console.WriteLine("STDERR: " + stderr.ToString());
Console.WriteLine("ExitCode is " + result.ExitCode);