【问题标题】:How to start a C program and send input from a file using the "gnome-terminal" command?如何使用“gnome-terminal”命令启动 C 程序并从文件发送输入?
【发布时间】:2013-09-12 18:59:57
【问题描述】:

为了澄清这个问题:我需要打开一个终端窗口,执行一个 C 程序(它从文件中获取输入)并将其输出保存到文件中。

我知道如果我执行“./program output.txt”,我会得到我想要的。

出于某种原因,如果我执行“gnome-terminal -e ./program output.txt”,程序会在不同的终端窗口中打开,但不会从 input.txt 中获取输入,也不会将输出保存到 output.txt 文件中。

我做错了什么?

【问题讨论】:

  • 因为您正在重定向当前终端会话的输入和输出(即执行 program 的那个)。
  • @GiuseppePes 那么如何重定向另一个会话(执行 ./program 的会话)的输入和输出?我已经尝试过 gnome-terminal -e "./program output.txt"

标签: c linux unix gnome-terminal


【解决方案1】:

您需要 bash 在新的 gnome 终端中重定向输入和输出。

    gnome-terminal -e 'bash -c "./program < input.txt > output.txt"'

【讨论】:

    【解决方案2】:

    试试gnome-terminal -e "./program &lt; input.txt &gt; output.txt"

    【讨论】:

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