将stdout/stderr重定向到多个文件 [英] Redirecting stdout/stderr to multiple files

查看:93
本文介绍了将stdout/stderr重定向到多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将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 go STDOUT
  • 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 to errorTestnormal.out, so it now contains all the STDOUT and STDERR output of script.pl.
  • Then, we write STDOUT of tee (which contains STDERR from script.pl) into errorTest.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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆