我正在嘗試將可執行控制檯應用程序的輸出轉換爲另一個。準確地說,我想要做什麼的一個小概述:從另一個可執行文件獲取輸出
我有一個可執行文件,我不能編輯,也沒有看到它的代碼。它在執行時寫入一些(很坦白地說)線到控制檯。
現在我想編寫另一個可執行文件來啓動上面的代碼並讀取它寫入的內容。
看起來很簡單給我,所以我就開始編碼,但結束了一個錯誤信息說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();
我可以打開可執行文件它也會打開裏面的內容,但一旦讀取返回的值,應用程序就會崩潰。
我在做什麼錯?
您可能感興趣的我對這個問題的答案:http://stackoverflow.com/questions/1096591 /如何隱藏cmd-window-while-running-a-batch-file/1096626#1096626 – 2009-11-09 12:47:21