我正在 Ubuntu
中使用 MonoDevelop
开发一个应用程序。通过这个应用程序,我需要运行终端命令并捕获它的输出。这样的事可能吗?任何帮助/想法将不胜感激!
我的意思是,如果用户单击按钮,命令将运行,输出将显示在文本框或其他内容中。我不想要弹出终端窗口,此操作应该完全在应用程序内部完成。
最佳答案
在 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();
关于c# - 如何在终端中运行命令并捕获输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12388912/