将stdout/stderr重定向到多个文件 [英] Redirecting stdout/stderr to multiple files
问题描述
我想知道如何将stderr重定向到多个输出.我使用此脚本进行了尝试,但无法使其正常运行.第一个文件应同时包含stdout和stderr,第二个文件应仅包含错误.
I was wondering how to redirect stderr to multiple outputs. I tried it with this script, but I couldn't get it to work quite right. The first file should have both stdout and stderr, and the 2nd should just have errors.
perl script.pl &> errorTestnormal.out &2> errorTest.out
是否有更好的方法可以做到这一点?任何帮助将非常感激.谢谢.
Is there a better way to do this? Any help would be much appreciated. Thank you.
推荐答案
perl script.pl 2>& 1> errorTestnormal.out |tee-errorTestnormal.out>errorTest.out
会做你想做的.
这有点混乱,让我们逐步进行一下.
This is a bit messy, lets go through it step by step.
- 我们说过去用于
STDERR
的内容现在将变为STDOUT
- 我们说过去用于
STDOUT
的内容现在将进入errorTestnormal.out.
- We say what used to go to
STDERR
will now goSTDOUT
- We say what used to go to
STDOUT
will now go to errorTestnormal.out.
现在,将 STDOUT
打印到文件中,将 STDERR
打印到 STDOUT
.我们想将 STDERR
放入2个不同的文件中,我们可以使用tee来完成.tee将给定的文本附加到文件中,并回显到 STDOUT
.
So now, STDOUT
gets printed to a file, and STDERR
gets printed to STDOUT
. We want put STDERR
into 2 different files, which we can do with tee. tee appends the text it's given to a file, and also echoes to STDOUT
.
- 我们使用
tee
附加到errorTestnormal.out
,因此它现在包含所有STDOUT
和STDERR
script.pl
的输出. - 然后,我们将
tee
的STDOUT
(其中包含来自script.pl
的STDERR
)写入errorTest.out
- We use
tee
to append toerrorTestnormal.out
, so it now contains all theSTDOUT
andSTDERR
output ofscript.pl
. - Then, we write
STDOUT
oftee
(which containsSTDERR
fromscript.pl
) intoerrorTest.out
此后, errorTestnormal.out
具有所有的 STDOUT
输出,然后具有所有的 STDERR
输出. errotTest.out
仅包含 STDERR
输出.
After this, errorTestnormal.out
has all the STDOUT
output, and then all the STDERR
output. errotTest.out
contains only the STDERR
output.
这篇关于将stdout/stderr重定向到多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!