System. Diagnostics. Process
Версия 3.3 от Alexandr Fokin на 2022/12/12 11:50
Process.start: how to get the output?
https://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output
EXECUTE A BASH SCRIPT VIA C#/.NET CORE
https://jackma.com/2019/04/20/execute-a-bash-script-via-c-net-core/
Template
ProcessStartInfo info = new ProcessStartInfo();
// fill info ...
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
//token.ThrowIfCancellationRequested();
using Process process = Process.Start(info);
try
{
await process.WaitForExitAsync(token);
}
catch (OperationCanceledException)
{
process.Kill(true);
await process.WaitForExitAsync();
throw;
}
var outputString = await process.StandardOutput.ReadToEndAsync();
var errorString = await process.StandardError.ReadToEndAsync();
if (process.ExitCode == 0)
{
//Successe
}
else
{
//Error
}
// fill info ...
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
//token.ThrowIfCancellationRequested();
using Process process = Process.Start(info);
try
{
await process.WaitForExitAsync(token);
}
catch (OperationCanceledException)
{
process.Kill(true);
await process.WaitForExitAsync();
throw;
}
var outputString = await process.StandardOutput.ReadToEndAsync();
var errorString = await process.StandardError.ReadToEndAsync();
if (process.ExitCode == 0)
{
//Successe
}
else
{
//Error
}