The problem with the example above is that I can’t catch error messages (STDERR) and print them to log file and the console. Any Idea how to handle the STDERR as well? Thanks.open(LOG, "> $LOG_FILE") || die "Can't redirect stdout"; #open(STDERR, ">&STDOUT") || die "Can't dup stdout"; open (CMD, " ls |"); while (<CMD>) { lprint ($_) } close(CMD); sub lprint () { my ($line) = @_; print LOG $line; # print STDERR $line; # print STDERR $_; print $line; }
In reply to Print STDOUT and STDERR to file and to console by Noame
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |