C#非空标准错误是否表示错误

时间:2021-07-19 22:41:33

标签: c# psexec standard-error

我正在尝试执行 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);
}

0 个答案:

没有答案
相关问题