【问题标题】:Redirecting the output of both stdout and stderr?重定向stdout和stderr的输出?
【发布时间】:2011-05-17 19:09:57
【问题描述】:

我有一个程序,它将其输出写入 stderr,它还在内部运行一个可执行文件 写入标准输出。我想使用重定向运算符将两者的输出重定向到同一个文件,例如“./a.out 2> output.txt”,但这会重定向标准错误,如何在此处指定标准输出。

【问题讨论】:

  • 这是一个很好的问题,但它属于 SuperUser,而不是 StackOverflow。

标签: redirect


【解决方案1】:

Linux 下:

./a.out > output.txt 2>&1

【讨论】:

  • 是的,它工作正常,但如果我写 1>&2,那么它不会重定向。你能解释一下这是什么意思吗?
  • 1>&2 将 stdout 定向到 stderr - 请参阅 tldp.org/LDP/abs/html/io-redirection.html 了解更多信息
【解决方案2】:

或者干脆

./a.out &> output.txt

【讨论】:

    猜你喜欢
    • 2014-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-07
    • 1970-01-01
    • 1970-01-01
    • 2010-11-28
    相关资源
    最近更新 更多