c# - 如何在终端中运行命令并捕获输出

标签 c# linux monodevelop

我正在 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/

相关文章:

c# - ILNumerics 在向量上的简单数学运算与系统数组和 Math.NET 的性能对比

c# - 为什么 Entity Framework Remove vs RemoveRange 返回类型不是 void 或 bool

linux - 如何 grep 查找文件中的某个键?

linux - C/C++格式字符串中的填充如何存储在Linux的虚拟内存中?

monodevelop 3 - 支持 "Attach to process"

android - 如何在monodroid中获取Camerapreview数据

c# - MonoDevelop 3.1.1 找不到 System.Xml.Linq

c# - 如何撤销用于阻止用户的引用 token ?

c# - 如何在c#中设置的2个单词字符串中拆分字符串

linux - Thingworx Composer 未加载