同时打印到标准输出和文件 [英] Printing to stdout and file simultaneously
本文介绍了同时打印到标准输出和文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有多个打印语句的 Perl 脚本.有没有一种方法可以将所有这些打印语句同时定向到文件和标准输出,而无需重复打印语句?
I have a Perl script with several print statements. Is there a way by which I can direct all of these print statements to a file as well as to stdout simultaneously without duplicating print statements ?
推荐答案
您可以使用 File::Tee.
use File::Tee qw(tee);
tee STDOUT, '>>', 'some_file.out';
print "w00p w00p";
如果 File::Tee
不可用,很容易用管道模拟:
If File::Tee
is unavailable, it is easily simulated with a pipeline:
open my $tee, "|-", "tee some_file.out";
print $tee "w00p w00p";
close $tee;
这篇关于同时打印到标准输出和文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文