2010-08-30 66 views
0

//通過此代碼我希望將要執行的批處理文件將顯示shell屏幕上的輸出,我得到RedirectStandardOutput = false;我想同時.RedirectStandardOutput = true/false

但我也希望在同一時間輸出應該重定向到一個日誌文件爲此我必須這樣做RedirectStandardOutput = true;

但一旦一個可以使用,也可以真正請幫我很大的編程人員...!

 System.Diagnostics.Process p = new System.Diagnostics.Process(); 
     p.StartInfo.FileName = "c:\test\build.bat"; 

     p.StartInfo.UseShellExecute = false; 

     p.StartInfo.RedirectStandardOutput = true; 


     p.Start(); 

     string output = null; 
     // try 
     // { 

      output = p.StandardOutput.ReadToEnd(); 

     // } 
     // catch (Exception ex) 
     // { 
     //  MessageBox.Show(ex.ToString()); 
     // } 

     System.IO.File.WriteAllText("c:\test\log.txt", output); 
+0

這是哪一種語言? C#?請用適當的語言標籤標記它。 – 2010-08-30 12:33:03

+0

請勿標記您的帖子,因爲您需要幫助。它濫用了調節系統。 – Will 2010-08-31 10:10:32

回答

1

你可以寫你收到p.StandardOutputConsole.Write輸出。
要查看輸出實時顯示,請將單個ReadToEnd呼叫替換爲ReadLine的循環呼叫。

+0

但這是我的Windows窗體應用程序如何使用console.write 我得到了一個輸出,當我使用p.StartInfo.RedirectStandardOutput = false;但如果我使用「假」我無法重定向輸出在日誌文件中...我希望兩個PLZ給我解決方案:( – user434934 2010-08-31 04:31:44