我正在尝试执行 psexec 进程,即使该进程运行良好,标准错误也不为空。这不是通过查看标准错误是否为空字符串来检查错误的好方法吗?
string psexcFn = @"c:\pspec\psexec.exe";
ProcessStartInfo p = new ProcessStartInfo(psexcFn);
p.UseShellExecute = false;
p.RedirectStandardError = true;
p.RedirectStandardOutput = true;
var proc = System.Diagnostics.Process.Start(p);
//If StandardError string not empty, throw exception.
string stderr = proc.StandardError.ReadToEnd().Trim();
if (stderr.Length > 0)
{
throw new Exception("StandardError: " + stderr);
}