【发布时间】:2010-12-14 14:45:52
【问题描述】:
我目前正在尝试将可执行控制台应用程序的输出转换为另一个。确切地说,是对我正在尝试做的事情的一些概述:
我有一个无法编辑的可执行文件,也看不到它的代码。它在执行时会在控制台中写入一些(老实说相当多的)行。
现在我想编写另一个可执行文件来启动上面的那个并读取它写入的内容。
对我来说似乎很简单,所以我开始编码,但最终收到一条错误消息,指出 StandardOut has not been redirected or the process hasn't started yet.
我尝试过使用这种结构(C#):
Process MyApp = Process.Start(@"C:\some\dirs\foo.exe", "someargs");
MyApp.Start();
StreamReader _Out = MyApp.StandardOutput;
string _Line = "";
while ((_Line = _Out.ReadLine()) != null)
Console.WriteLine("Read: " + _Line);
MyApp.Close();
我可以打开可执行文件,它也可以打开里面的那个,但是一旦读取返回值,应用程序就会崩溃。
我做错了什么?!
【问题讨论】:
-
您可能对我对这个问题的回答感兴趣:stackoverflow.com/questions/1096591/…
标签: c# redirect executable console-application