0

I am running an exe file from C# code, due to some reasons error occurs in that exe file. It keeps waiting and ultimately gives a popup error "abc.exe has stopped working" and so on, but it does not exit.

 //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;
                }
            }

Though I can capture exit code, but I can do so only if it exits.

SMT
  • 469
  • 1
  • 5
  • 17
  • command line exe or is there GUI? – Sarvesh Mishra Aug 11 '15 at 09:33
  • possible duplicate of [catch another process unhandled exception](http://stackoverflow.com/questions/2279181/catch-another-process-unhandled-exception) – Rohit Aug 11 '15 at 09:36
  • @Sarvesh There is no GUI, just an exe file – SMT Aug 11 '15 at 09:59
  • Exceptions are isolated to their own processes. Unless you want to write half a debugger so that you can load the other exe, install an (unmanaged) unhandled exception handler and then run the exe, you won't be able to catch an exception thrown in another process. – Damien_The_Unbeliever Aug 11 '15 at 10:11
  • You might want to review the event log on that system - `has stopped working` messages are sometimes accompanied by an entry there with more information. – 500 - Internal Server Error Aug 11 '15 at 11:14

1 Answers1

0

This link might be useful https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandarderror%28v=vs.110%29.aspx

Subscribe to ErrorDataReceived event and get the error message. enter link description here

Instead of waiting for it to exit, you can subscribe to Process Exit event

If your exe is giving some kind of unhandled exception, you won't be able to get the exact error. Windows event viewer may help you in getting the error number and possible causes.

Sarvesh Mishra
  • 2,014
  • 15
  • 30