如何在运行进程时显示控制台?

时间:2015-06-18 10:54:39

标签: c# bash process

我正在尝试在控制台窗口中启动命令/我正在使用gtk表单/
所以我试着用这种方式启动它:

Process p = new Process ();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "bash";
p.StartInfo.CreateNoWindow = false;
p.StartInfo.Arguments ="/tmp/test.sh";
p.Start ();
p.WaitForExit ();

但它不会显示任何东西 对于那些只使用Windows的人来说,就像这样:

p.StartInfo.FileName = "cmd";
p.StartInfo.Arguments =" c:\\test.bat";

我试图将UseShellExecute更改为true但问题仍然存在。
任何想法??

1 个答案:

答案 0 :(得分:1)

Bash运行脚本但是如果要查看输出,则需要在终端中运行它。

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "gnome-terminal"; // Replace with whichever terminal you want to use
p.StartInfo.CreateNoWindow = false;
p.StartInfo.Arguments ="-x bash /tmp/test.sh";
//p.StartInfo.Arguments ="-e \"bash -c /tmp/test.sh;bash\""; // Use this if you want the terminal window to stay open
p.Start();
p.WaitForExit();