【问题标题】:Catching STDOUT and STDERR with pipes on next command as separated arguments?将下一个命令上的管道作为单独的参数捕获 STDOUT 和 STDERR?
【发布时间】:2019-10-26 11:39:41
【问题描述】:

是否可以有一个命令将 STDOUT 和 STDERR 作为单独的流捕获以用作下一个命令中的参数?

就是一个例子。

# foo outputs to stdout and stderr
# bar recieves in -i and -j streams that could be files but in general they are streams, so it would make sence to pipe to any of this two. 
$ foo | bar -i - -j -&2 

我可以在 bash 中执行此操作吗?还是在其他外壳中?

【问题讨论】:

    标签: shell pipe stdout stdin stderr


    【解决方案1】:

    您可以在命名管道的帮助下做到这一点:

    mkfifo /tmp/whatever
    foo 2>/tmp/whatever | bar -i - -j /tmp/whatever
    

    实际上没有数据写入/tmp/whatever。内核将写入进程的输出直接发送给读取进程。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 2022-11-20
      • 2015-06-21
      • 2021-09-05
      • 1970-01-01
      • 2012-02-26
      相关资源
      最近更新 更多