从进程中获取返回值 [英] Get return value from process

查看:46
本文介绍了从进程中获取返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行以下操作:我有一个可以接受参数(数字)的过程并返回这些数字的总和

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;

我从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

int result = P.ExitCode;

我有一个例外..我的问题是如何等待这个过程完成它的工作抱歉我忘了说我正在使用 C# 语言

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

推荐答案

use:

Process P = Process.Start(sPhysicalFilePath, Param);
P.WaitForExit();
int result = P.ExitCode;

来自 MSDN

这篇关于从进程中获取返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆