如何捕获或重定向针对 a 发生的错误Process
?
我希望能够获得错误消息信息。
下面的代码不这样做。
try
{
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = process_to_run;
myProcess.StartInfo.Arguments = p_arg + " > "+process_to_run+".txt 2>&1";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
myProcess.WaitForExit();
}
catch (Exception ep)
{
richTextBox1.AppendText("\n" + ep.Message);
time_date = get_time();
log_file.Write(time_date);
log_file.WriteLine(process_to_run + "...Failed. ERROR: " + ep.Message);
}