C# 从进程中获取返回值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1585354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get return value from process
提问by Hany
Hi I am trying to do the following: I have a process which can take parameters (digits) and return the sum of these numbers
嗨,我正在尝试执行以下操作:我有一个可以接受参数(数字)并返回这些数字之和的过程
Process P = Process.Start(sPhysicalFilePath, Param);
int result = P.ExitCode;
I get the return value from "ExitCode" the problem is: the program sometimes finishes his work before the process so when the program reaches this line
我从“ExitCode”得到返回值,问题是:程序有时会在进程之前完成他的工作,所以当程序到达这一行时
int result = P.ExitCode;
I got an exception .. my question is how to wait this process until it finishes its work sorry I forget to say that's I am working with C# language
我有一个例外..我的问题是如何等待这个过程直到它完成它的工作对不起我忘记说我正在使用 C# 语言
采纳答案by snicker
回答by Bahaa J.
You can try the below code:
你可以试试下面的代码:
Dim P As New Process
P = Process.Start(info)
P.WaitForExit()
fichiersATraiter = P.ExitCode
Hope this helps :)
希望这可以帮助 :)