【发布时间】:2015-08-11 18:17:25
【问题描述】:
我正在从 C# 代码运行一个 exe 文件,由于某些原因,该 exe 文件中出现错误。它一直在等待,最终弹出错误“abc.exe 已停止工作”等,但它并没有退出。
//The below code is calling it successfully
public bool callExe(string exePath)
{
Log("EXE excution Started : " + exePath, INFO_TAG);
try
{
Process exeProcess = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = exePath;
exeProcess.StartInfo = startInfo;
startInfo.Arguments = this.prjId.ToString();
exeProcess.Start();
exeProcess.WaitForExit();
int exitCode = exeProcess.ExitCode;
return true;
}
catch (Exception e)
{
errorCode = EXE_ERROR;
return false;
}
}
虽然我可以捕获退出代码,但只有在它退出时才能这样做。
【问题讨论】:
-
命令行exe还是有GUI?
-
@Sarvesh 没有 GUI,只有一个 exe 文件
-
异常被隔离到它们自己的进程中。除非您想编写半个调试器以便加载另一个 exe,安装(非托管)未处理的异常处理程序然后运行该 exe,否则您将无法捕获另一个进程中抛出的异常。
-
您可能想要查看该系统上的事件日志 -
has stopped working消息有时会伴随有一个包含更多信息的条目。