用C#检查进程运行结果
这篇文章具有以下代码。
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
评论说我需要检查返回代码,但 p.WaitForExit()
不返回任何内容。
- Q1 : 我需要检查什么返回码?
- Q2 : 通常如何检查运行进程是否正常?
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 code do I need to check?
- Q2 : Normally, how one can check if running process is OK or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于 Q1,检查 Process.ExitCode 属性。
对于 Q2,成功和失败的退出代码由被调用进程本身定义,但通常 0 表示成功,其他任何值表示失败。
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.
只需查看 ExitCode 属性即可查看是否这个过程是否愉快地退出。
对于正在运行的进程,您可以查看标准错误流以查看是否有任何消息打印在那里。它们很可能代表某种问题,但这比退出代码更依赖于实现。
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.
进程完成后,System.Diagnostics.Process 对象实例的属性
ExitCode
应包含程序状态代码。After the process completes, the property
ExitCode
of the System.Diagnostics.Process object instance should contain the program status code.只需在进程退出后检查即可
。
Process.ExitCode 属性
Just check
after process exits.
Process.ExitCode Property