如何取得其它程序輸出結果

主題: 如何獲取控制檯程序的運行結果?
作  者: 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

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdiagnosticsprocessstartinfoclassredirectstandardoutputtopic.asp

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();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章