首页 文章

将stderr重定向到stdout和一个单独的文件? - perl,linux [duplicate]

提问于
浏览
1

这个问题在这里已有答案:

我想将stdout和stderr重定向到file1,但也只将stderr重定向到file2 . 这可能吗?我有一个第1部分的工作脚本,但无法弄清楚如何另外将stderr写入file2,而不会覆盖重定向到file1(实际上,第一个stderr重定向将转到stdout然后转到file1) . 我正在尝试这样做,因此file1可以包含打印语句和错误,就像我在控制台中运行一样,而file2只会记录错误 .

有没有想过最好的方法来实现这个目标而不会偏离我已经拥有的东西?

open STDOUT, '>', "$file1" or die $!; # redirect stdout to file
open STDERR, '>&STDOUT' or die $!; # redirect standard error to stdout
# now how to *also* redirect STDERR to $file2?

谢谢

Edit :我不相信这是this question的重复;它是,我想要(或者可以't see) any output on the screen. This is like my 3rd time writing in perl so it'对我来说很新 . 我've been looking at this for hours (including already looking at the '重复' post you linked), and can'找到一个合理的解决方案来解决我的问题 .

1 回答

  • 3

    您可以尝试使用Perl模块IO::Tee,它允许您将输出重定向到多个输出句柄 .

相关问题