2012-09-12 173 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

这实际上是从微软例子:)拍摄 –