Одновременное тестирование (обращение) нескольких ячеек в одном диапазоне при использовании формулы массива

Легче просто захватить вывод из StandardOutput и StandardError , сохранить каждый вывод в StringBuilder и использовать этот результат когда процесс завершен.

var sb = new StringBuilder();

Process p = new Process();

// redirect the output
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;

// hookup the eventhandlers to capture the data that is received
p.OutputDataReceived += (sender, args) => sb.AppendLine(args.Data);
p.ErrorDataReceived += (sender, args) => sb.AppendLine(args.Data);

// direct start
p.StartInfo.UseShellExecute=false;

p.Start();
// start our event pumps
p.BeginOutputReadLine();
p.BeginErrorReadLine();

// until we are done
p.WaitForExit();

// do whatever you need with the content of sb.ToString();

Вы можете добавить дополнительное форматирование в оператор sb.AppendLine, чтобы различать стандартный вывод и вывод ошибки, например: sb.AppendLine("ERR: {0}", args.Data);

0
задан Community 11 July 2019 в 10:34
поделиться