使用Process.Start捕获控制台输出 [英] Using Process.Start to capture console output

查看:502
本文介绍了使用Process.Start捕获控制台输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,我是C#的新手,这应该是一个愚蠢的问题,但是我需要它,希望有人能提供帮助.

unfortunately i'm new in C# and this should be a stupid question but i need it, hope someone should help..

基于本文: http://csharptest.net/532/using-processstart-to-capture-console-output/

我需要使用第一个代码示例,但是像作者所描述的那样应用第二个代码示例.他曾一度谈论过在第一个代码中替换第二个代码,但我真的不明白要删除和/或替换多少个代码.

i need to use the first code example but applying the second one like described by the Author. He talk about substitute the second code in the first at one point, but i really don't understand how many code to delete and/or substitute..

如果可能的话,我想举个可行的例子...

If it's possible i like to have a working example of that...

在此先感谢您的帮助:-)

Thanks in advance for the help :-)

推荐答案

给出说明:

您将删除事件订阅和对process.BeginOutputReadLine()

他在谈论这两行:

process.OutputDataReceived += (o, e) => { if (e.Data == null) mreOut.Set(); else output(e.Data); };
process.BeginOutputReadLine();

请注意,您要替换的代码应该只是:

Note that the code you substitute to this should be just:

new ReadOutput(process.StandardInput, mreOut);

ReadOutput类将位于Run方法之外(由于在C#中,方法不能包含类).

ReadOutput class would be outside the Run method (since in C#, methods cannot contain classes).

这篇关于使用Process.Start捕获控制台输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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