简体   繁体   English

识别由C#Process.Start()运行的可执行文件崩溃

[英]Identify crash of executable run by C# Process.Start()

My code: 我的代码:

ProcessInfo processInfo = ...
Process proc = Process.Start(processInfo);
proc.WaitForExit();
if (proc.ExitCode != 0)
{
   // ...
}

My problem is that the process (a C++ executable) is sometime crashing due to unhandled exceptions, in unknown circumstances. 我的问题是在未知情况下,由于未处理的异常,进程( C++可执行文件)有时会崩溃。

I can tell that the executable crashed, since on crash it returns a negative exit code (or non zero for that matter). 我可以说可执行文件崩溃了,因为崩溃时它返回一个负的退出代码(或非零)。 However, I cannot create a process dump to investigate. 但是,我无法创建进程转储进行调查。

If I at least had Windows' "Program stopped working" message popped, then I could create the dump manually. 如果至少弹出Windows的“程序停止工作”消息,则可以手动创建转储。

Of course I can use software like Debug Diag to monitor executables and take dump on crash, but would rather have a more generic in-house solution. 当然,我可以使用Debug Diag类的软件来监视可执行文件并在崩溃时进行转储,但宁愿拥有更通用的内部解决方案。

I think it's really up to the executable being called to output the error. 我认为这取决于可执行文件被输出以输出错误。 Wether it outputs to the window or puts an entry in the event viewer etc is up to the application in question. 它是否输出到窗口或在事件查看器中放置条目等取决于所讨论的应用程序。 You should be able to read the output messages. 您应该能够阅读输出消息。

Have you tried to capture the stdErr output in addition to stdOut? 您是否已尝试捕获除stdOut之外的stdErr输出?

For example: 例如:

Process installProcess = new Process 
{ 
    StartInfo = 
    {
        FileName = exeName,
        Arguments = args,
        CreateNoWindow = true,
        UseShellExecute = false,
        WindowStyle = ProcessWindowStyle.Hidden,
        RedirectStandardOutput = true,
        RedirectStandardError = true
    }
};

installProcess.Start();

string processStandardOutput = installProcess.StandardOutput.ReadToEnd();
string processStandardError = installProcess.StandardError.ReadToEnd();

// Check both strings for !IsNullOrEmpty and log something of interest

installProcess.WaitForExit();
ExitCode = installProcess.ExitCode;

// If ExitCode < 0, log the StandardError output...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM