Noame has asked for the wisdom of the Perl Monks concerning the following question:
The codes above prints the STDOUT to log file and to the screen as I need!!! But how can I control the STDERR handler? For example - If I change the CMD command in order to get an error message:my $LOG_FILE = "$HOME/log/test.txt"; open(LOG, "> $LOG_FILE") || die "Can't redirect stdout"; open (CMD, "ls |"); while (<CMD>) { lprint ($_) } close(CMD); sub lprint () { my ($line) = @_; print LOG $line; print $line; }
Then I should fail and get an error message - I want to print the error message to the log file and to the screen. Please advice.From: open (CMD, "ls |"); To: open (CMD, "ls_non_command |");
|
|---|