捕获C#从另外一个C#程序输出的可执行文件 [英] Capturing an c# executable output from another C# program

查看:148
本文介绍了捕获C#从另外一个C#程序输出的可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我执行C#程序即可以从另一C#程序中的.exe文件。但该.exe有一定的Console.WriteLine()的方案。我想要得到的标准输出到我的C#程序。

I am executing a C# program i.e a .exe from another C# program. but the .exe has some Console.WriteLine() in its program. I want to get the standard output into my C# program.

例如,

考虑一个C#可执行即1.EXE,有另一个计划2.cs。

Consider a C# executable i.e 1.exe and there is another Program 2.cs.

我是从2.cs 1.EXE调用。现在有在控制台从1 exe文件显示一些输出。但我想在我的程序2.cs.的输出中用于显示信息给用户。

I am calling from 2.cs 1.exe. Now there is some output that the console is displaying from 1. exe. But I want the ouput in my program 2.cs. for displaying information to user.

这可能吗?请帮忙

谢谢 西娜斯迪胡

推荐答案

您可以使用ProcessStartInfo.RedirectStandardOutput地产

You can use ProcessStartInfo.RedirectStandardOutput Property

Process compiler = new Process();
compiler.StartInfo.FileName = "csc.exe";
compiler.StartInfo.Arguments = "/r:System.dll /out:sample.exe stdstr.cs";
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();    

Console.WriteLine(compiler.StandardOutput.ReadToEnd());

compiler.WaitForExit();

<一个href="http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput.aspx">http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput.aspx

这篇关于捕获C#从另外一个C#程序输出的可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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