Perl:将STDOUT重定向到两个文件
发布时间:2020-12-15 21:27:07 所属栏目:大数据 来源:网络整理
导读:如何将STDOUT流重定向到我的Perl脚本中的两个文件(重复)?目前我只是流入一个单一的日志文件: open(STDOUT,"$out_file") or die "Can't open $out_file: $!n"; 我需要改变什么?谢谢. 解决方法 您也可以使用 IO::Tee . use strict;use warnings;use IO::Te
如何将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! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |