1

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.

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.

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.

Mugen
  • 8,301
  • 10
  • 62
  • 140

2 Answers2

1

Have you tried to capture the stdErr output in addition to stdOut?

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...
JHobern
  • 866
  • 1
  • 13
  • 20
0

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.