从其他控制台应用程序运行控制台应用程序 [英] Run console application from other console app

查看:116
本文介绍了从其他控制台应用程序运行控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#控制台应用程序(A)。我想在B使用相同的命令窗口这样的方式执行从一个应用程序内的其他控制台应用程序(B)(以同步的方式)。当B存在,A应该能看懂B的退出code。

I have a C# console application (A). I want to execute other console app (B) from within app A (in synchronous manner) in such way that B uses the same command window. When B exists, A should be able to read B's exit code.

如何做到这一点?我只需要了解如何运行相同的cmd窗口此应用程序的其他这个小技巧。

How to do that? I need only this little tip on how to run this other app in same cmd window.

推荐答案

您可以使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx\"><$c$c>Process.Start启动其他控制台应用程序。

You can use Process.Start to start the other console application.

您将需要构造进程<一个href=\"http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput.aspx\"><$c$c>ProcessStartInfo.RedirectOutput设置为真正和<一个href=\"http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.useshellexecute.aspx\"><$c$c>UseShellExecute设置为,以便能够利用自己的输出。

You will need to construct the process with ProcessStartInfo.RedirectOutput set to true and UseShellExecute set to false in order to be able to utilize the output yourself.

您可以再读取使用输出<一个href=\"http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx\"><$c$c>StandardOutput.ReadToEnd上的处理。

You can then read the output using StandardOutput.ReadToEnd on the process.

这篇关于从其他控制台应用程序运行控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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