在下一个命令中使用管道作为分隔参数捕获 STDOUT 和 STDERR?

Catching STDOUT and STDERR with pipes on next command as separated arguments?

是否可以有一个命令将 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?

您可以在命名管道的帮助下完成此操作:

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

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