in reply to Logging output of a script to screen AND file
#!/usr/bin/perl use strict; use warnings; use diagnostics; open(LOG, '>', 'LOG_FILE') or die "Can't redirect stdout: $!"; open(CMD, 'ls |'); open(STDERR, '>&', STDOUT) or die "Can't redirect stderr: $!"; open(STDERR, '>', 'LOG_FILE') or die "Can't redirect stderr: $!"; print "LOG_FILE\n"; while (<CMD>) { print_stuff ($_); } sub print_stuff { my ($line) = @_; print LOG $line; print $line; } close(CMD) or die "close CMD failed: $!"; exit 0;
|
|---|