System.Diagnostics.Process
Версия 2.1 от Alexandr Fokin на 2022/06/06 14:40
Process.start: how to get the output?
https://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output
Template
ProcessStartInfo info = new ProcessStartInfo();
// fill info ...
//token.ThrowIfCancellationRequested();
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 ...
//token.ThrowIfCancellationRequested();
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
}