Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ?

Like in Shell script, we use tee, is there anything in Perl or any other option ?

Have you checked CPAN? Else you can program it in Perl, simply for opening another file for appending and writing to this file in addition to printing to the screen

1 Like

Yes...found a way.

open (STDOUT, "| tee -ai log.txt");
print "blah blah";
close (STDOUT);

This works perfectly. Thanks ghostdog74 :slight_smile: