如何取得其它程序输出结果

主题: 如何获取控制台程序的运行结果?
作  者: 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();

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