2012-09-12 170 views
0

我在Ubuntu使用MonoDevelop的應用程序的工作。通過這個應用程序,我需要運行一個終端命令並捕獲它的輸出。這樣的事情可能嗎?任何幫助/想法將不勝感激!如何在終端運行命令並捕獲輸出

我的意思是,如果一個按鈕用戶點擊,該命令將運行並輸出將被顯示在文本框或東西。我不希望一個終端窗口彈出,這個動作應該在應用程序內完全完成。

回答

0

在C#中的Windows,你這樣做:

Process p = new Process(); // Redirect the output stream of the child process. 
p.StartInfo.RedirectStandardOutput = true; 
p.StartInfo.FileName = "program.exe"; 
p.Start(); // Do not wait for the child process to exit before reading to the end of its  redirected stream. 
p.WaitForExit(); // Read the output stream first and then wait. 
string output = p.StandardOutput.ReadToEnd(); 
p.WaitForExit(); 
+0

過程實現IDisposable,最好是不能離開它掛在這樣;) –

+0

這實際上是從微軟例子:)拍攝 –