我可以将STDOUT和STDERR发送到日志文件,也可以发送到Win32 Perl中的屏幕吗? [英] Can I send STDOUT and STDERR to a log file and also to the screen in Win32 Perl?

查看:57
本文介绍了我可以将STDOUT和STDERR发送到日志文件,也可以发送到Win32 Perl中的屏幕吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了Internet,并找到了一些很好的解决方案,可以将STDOUT放到两个不同的地方.就像日志文件一样,同时也喜欢屏幕.这是一个示例:

I've searched the Internet and have found some good solutions for teeing STDOUT to 2 different places. Like to a log file and also to the screen at the same time. Here's one example:

use IO::Tee;
my $log_filename = "log.txt";
my $log_filehandle;
open( $log_filehandle, '>>', $log_filename )
  or die("Can't open $log_filename for append: $!");
my $tee = IO::Tee->new( $log_filehandle, \*STDOUT );
select $tee;

但是此解决方案使STDERR只进入屏幕,而我希望STDERR既进入屏幕,也进入到STDOUT正在登录的同一日志文件.那有可能吗?

But this solution leaves STDERR going only to the screen and I want STDERR go to both the screen and also to the same log file that STDOUT is being logged to. Is that even possible?

我的任务是记录构建过程,但我也想像往常一样在IDE屏幕上看到它.记录错误消息与记录快乐消息一样重要.将错误记录到单独的日志文件中并不是一个好的解决方案.

My task is to get my build process logged, but I also want to see it on my IDE's screen as usual. And logging the error messages is just as important as logging the happy messages. And getting the errors logged to a separate log file is not a good solution.

推荐答案

您可以在Windows Shell级别将stderr重定向到stdout,方法是:

You can redirect stderr to stdout at the windows shell level by doing something like:

perl stuff.pl 2>&1

有关官方用词,请参见此处的支持文章.

See support article here for the official word.

然后,您可以使用

Then you could use this stackoverflow answer to do a tee from the shell.

perl stuff.pl 2>&1 | tee stuff.txt

这篇关于我可以将STDOUT和STDERR发送到日志文件,也可以发送到Win32 Perl中的屏幕吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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