Checking the result of running process with C#
This post has the following code.
Process p = new Process();
StringBuilder sb = new StringBuilder("/COVERAGE ");
sb.Append(exeFileName);
p.StartInfo.FileName = "vsinstr.exe";
p.StartInfo.Arguments = sb.ToString();
p.Start();
p.WaitForExit();
// Look at return code – 0 for success
The comment says I need to check the return code, but p.WaitForExit()
doesn't return anything.
- Q1 : What return c开发者_运维问答ode do I need to check?
- Q2 : Normally, how one can check if running process is OK or not?
For Q1, check the Process.ExitCode
property.
For Q2, exit codes for success and failure are defined by the called process itself, but conventionally 0 indicates success and anything else indicates failure.
just look at the ExitCode property to see if the process exited happily or not.
With respect to a running process, you can watch the standard error stream to see if any messages are printed there. Chances are they will represent some kind of problem, but this is even more implementation-dependant than the exit code.
After the process completes, the property ExitCode
of the System.Diagnostics.Process object instance should contain the program status code.
Just check
p.ExitCode
after process exits. Process.ExitCode Property
精彩评论