如何将STDOUT流重定向到我的Perl脚本中的两个文件(重复)?目前我只是流入一个单一的日志文件:
open(STDOUT,">$out_file") or die "Can't open $out_file: $!\n";
我需要改变什么?谢谢.
解决方法
您也可以使用
IO::Tee
.
use strict; use warnings; use IO::Tee; open(my $fh1,">","tee1") or die $!; open(my $fh2,"tee2") or die $!; my $tee=IO::Tee->new($fh1,$fh2); select $tee; #This makes $tee the default handle. print "Hey!\n"; #Because of the select,you don't have to do print $tee "Hey!\n"
是的,输出工作:
> cat tee1 Hey! > cat tee2 Hey!