Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing to stdout and file simultaneously [duplicate]

Tags:

stdout

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 ?

like image 891
Jean Avatar asked May 20 '13 15:05

Jean


1 Answers

You can use File::Tee.

use File::Tee qw(tee);

tee STDOUT, '>>', 'some_file.out';

print "w00p w00p";

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;
like image 58
friedo Avatar answered Nov 11 '22 21:11

friedo