这个问题困扰我有一段时间了。是否可以将 stdout
和 stderr
重定向到终端输出和一个程序?
我知道可以使用tee
将输出重定向到文件和 stdout
,但我希望它既能传输到一个程序(我的编辑器 [TextMate]),又能传输到终端输出… 这肯定是可能的(我知道在 zsh 中是可能的…)
mkfifo some_pipe
command_that_writes_to_stdout | tee some_pipe \
& command_that_reads_from_stdin < some_pipe
rm some_pipe
或者,在Bash中:
command_that_writes_to_stdout | tee >(command_that_reads_from_stdin)
|&
代替|
,那么bash会同时重定向标准输出和标准错误输出。 - jfs如何将stdout和stderr同时重定向到终端输出和程序中?
我不确定将stdout和stderr合并后输入到编辑器是否有用,但是像这样做是否可以满足您的需求?
input_prog 2>&1 | tee /dev/tty | my_editor
/dev/stdout
和/dev/stderr
。 - JasonSmith实际上我并不确定TextMate是否可以将文件作为标准输入进行编辑,这似乎有些奇怪。我猜想你可能希望将stdout/stderr发送到一个文件中,并在那里进行编辑,此时您需要执行以下操作:
progname 2>&1 | tee tempfile ; textmate tempfile
2>&1
将标准错误输出(文件句柄2)重定向到与标准输出(文件句柄1)相同的位置,使它们都进入单个流中。然后tee
命令将其写入tempfile
以及stdout
。progname 2>&1 | tee /dev/tty | textmate