环境:net6
nuget包:Cliwrap 3.6.7
program:
相当于cmd运行命令:nuget search json
static async Task Main(string[] args)
{
var cmd = Cli.Wrap("D:\\软件\\Nuget\\nuget.exe").WithArguments(args =>
args.Add("search").Add("json"));
await foreach (var cmdEvent in cmd.ListenAsync())
{
switch (cmdEvent)
{
case StartedCommandEvent started:
Console.WriteLine($"Process started; ID: {started.ProcessId}");
break;
case StandardOutputCommandEvent stdOut:
Console.WriteLine($"Out> {stdOut.Text}");
break;
case StandardErrorCommandEvent stdErr:
Console.WriteLine($"Err> {stdErr.Text}");
break;
case ExitedCommandEvent exited:
Console.WriteLine($"Process exited; Code: {exited.ExitCode}");
break;
}
}
}
output: