【问题标题】:Redirect stdin and stdout in terminal to test program将终端中的标准输入和标准输出重定向到测试程序
【发布时间】:2020-10-01 22:04:15
【问题描述】:

我有一个从标准输入读取并输出到标准输出的程序。我希望能够通过终端进行测试。

我知道

./program < input_file       # Redirects stdin

./program > output_file      # Redirects stdout

output_file < ./program < input_file # Is this supposed to redirect stdin and stdout at the same time?

如果我想将test.out 中的示例输出与output_file 进行比较怎么办?我怎样才能一口气做到这一点?

我尝试了各种方法,但到目前为止都没有运气。

【问题讨论】:

  • ././program &lt; input_file &gt; output_file 应该可以工作

标签: c terminal stdout stdin io-redirection


【解决方案1】:

您对输出文件的重定向错误。您需要使用&gt;,而不是&lt;,并且它必须放在文件名之前。就像在您的第二个示例中一样 - 当您重定向输入和输出时没有什么不同。

./program < input_file > output_file

您写的内容是运行名为output_file 的程序,并首先将其输入从./program 重定向,然后从input_file 重定向。

【讨论】:

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