【问题标题】:How run a command, show stderr on screen, and at the same time, save stderr in a file如何运行命令,在屏幕上显示标准错误,同时将标准错误保存在文件中
【发布时间】:2021-04-28 07:23:09
【问题描述】:

我想运行一个命令,在屏幕上显示标准错误,同时将标准错误保存在一个文件中。

【问题讨论】:

    标签: bash stderr io-redirection


    【解决方案1】:

    在 bash(或 zsh)中,您可以通过 process substitution 将 stderr 重定向到 tee

    somecommand 2> >(tee errors.log)
    

    【讨论】:

      【解决方案2】:

      此命令在屏幕上显示 stdout 和 stderr 并将 stderr 保存在 /tmp/errors 上:

      $ ( ls file_do_not_exist /bin/true 2>&1 1>&3 | tee /tmp/errors 1>&2; ) 3>&1
      

      【讨论】:

        猜你喜欢
        • 2013-10-16
        • 1970-01-01
        • 1970-01-01
        • 2013-05-11
        • 1970-01-01
        • 1970-01-01
        • 2015-03-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多