如何从exe获取返回值并重新启动它
场景:我有一个MFC代码,它调用一个用C#创建的exe(它是一个Windows窗体应用程序)
需求:我需要exe在关闭时返回一个值,并且根据返回值,相同的 exe 将再次启动
psudocode
int result = RunExe("exename", arguments)
if(result == 1)
{
result = RunExe("exename", arguments)
}
我是否必须将 if 条件放入循环中?
请给我一些建议。 1.如何从exe返回值 2. 如何收取返回值 3.如何重新启动exe
Scenario: I have a MFC code which call an exe created in C# (it is a windows form application)
Need: I need that the exe would return a value when closed and on the basis of the return value the same exe will started again
psudocode
int result = RunExe("exename", arguments)
if(result == 1)
{
result = RunExe("exename", arguments)
}
do I have to put the if condition in loop?
plz give me some suggestion.
1.How to return a value from exe
2. How to collect the return value
3. How to restart the exe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的 C# EXE 可以返回这样的 int 值:
您的其他应用程序必须像此处其他应用程序所解释的那样处理返回值。
Your C# EXE can return an int value like this:
Your other app has to handle the return value like the others here has explained.
下面的方法应该可以解决问题;
然后像这样称呼它;
The following method should do the trick;
Then call it like so;
您可以使用 process.ExitCode 并创建一个新的 EXE 来控制退出值并启动原始 EXE如果需要,或者如果信息大于整数,则将信息保存在磁盘上的文件中,以便您可以从父进程(您创建的新 EXE)处理它。
you can use the process.ExitCode and create a new EXE which controls the exitvalue and starts the original EXE if needed, or you save the information in a file on the disk if its more than an integer so you can process it from the parent process (the new EXE you create).
就像OD所写的那样,
Process.ExitCode
是您正在寻找的值...要启动进程,您可以使用
Process.Start(string_path_to_exe,string_args)
它将返回一个表示已启动进程的进程对象...要等待进程结束,请使用该对象的WaitForExit()
方法,请参阅进程类 @ MSDN
like O.D wrote,
Process.ExitCode
is the value you are looking for ...to start the process you can use
Process.Start(string_path_to_exe,string_args)
which will return a Process object that represents the started process ... to wait until the process has ended use theWaitForExit()
method of that objectsee Process Class @ MSDN