主題: | 如何獲取控制檯程序的運行結果? | |
作 者: | answered (愛才的) | |
等 級: | ||
信 譽 值: | 100 | |
所屬社區: | .NET技術 C# | |
問題點數: | 100 | |
回覆次數: | 3 | |
發表時間: | 2005-02-28 22:36:23 |
我想做個程序,就象EditPlus或VS.net2003下方的編譯輸出窗口一樣,編譯時下方有一個輸出窗口顯示當前編譯的情況。
舉個例子,比如我點擊窗體上的一個按鈕(按鈕的作用是執行csc c:/a.cs),我想把這個csc c:/a.cs的結果給顯示到this窗體中來,請給個思路或代碼可以不?
use System.Diagnostics.Process to run your command, and read from its StandardOutput, for example, see
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "test.exe";
p.Start();
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();