将 stdout 重定向到 stderr 但也将其保留在 stdout 中
Redirect stdout to stderr but keep it also in stdout
我希望能够将 stdout
重定向到 stderr
,但也将 stdout
的内容保留在那里。
所以不完全是重定向,而是 clone
或 duplicate
.
找到解决方案:
mycommand | awk '{print; print | "cat 1>&2"}' > /tmp/stdout-content
# and stout is also in stderr (visible in the terminal)
通常:
command | tee /dev/stderr
如果唯一的目的是将 stdout 拆分为终端和文件,另一个想法:
mycommand | tee -a /tmp/stdout-content
注意: -a
表示附加到文件;要在每次 mycommand
为 运行 时覆盖文件,您可以删除 -a
(这会让您得到 KamilCuk 刚刚发布的相同内容)
我希望能够将 stdout
重定向到 stderr
,但也将 stdout
的内容保留在那里。
所以不完全是重定向,而是 clone
或 duplicate
.
找到解决方案:
mycommand | awk '{print; print | "cat 1>&2"}' > /tmp/stdout-content
# and stout is also in stderr (visible in the terminal)
通常:
command | tee /dev/stderr
如果唯一的目的是将 stdout 拆分为终端和文件,另一个想法:
mycommand | tee -a /tmp/stdout-content
注意: -a
表示附加到文件;要在每次 mycommand
为 运行 时覆盖文件,您可以删除 -a
(这会让您得到 KamilCuk 刚刚发布的相同内容)