【问题标题】:How to show console when running a process?运行进程时如何显示控制台?
【发布时间】:2015-06-18 10:54:38
【问题描述】:

我正在尝试在控制台窗口中启动命令/我正在使用 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,但问题仍然存在..
有什么想法吗??

【问题讨论】:

  • 定义“它不会显示任何东西。”
  • 我想显示一个新的控制台.. 但我根本没有控制台窗口
  • 进程真的被创建了吗?你能看到它在运行吗?

标签: c# bash process


【解决方案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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-17
    • 1970-01-01
    相关资源
    最近更新 更多