in reply to Re^3: Print STDOUT and STDERR to file and to console
in thread Print STDOUT and STDERR to file and to console

Hi,

There is no other simple way? To print the STDERR and STDOUT to log file and to the console on threat?
Something like the following:
open(LOG, "> $LOG_FILE") || die "Can't redirect stdout"; #open(STDERR, ">&LOG") || 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; }

The problem with the example above is that I can’t catch an error messages (STDERR) and print them to log file and the console.
Any Idea how to handle the STDERR as well?

Thanks.

Replies are listed 'Best First'.
Re^5: Print STDOUT and STDERR to file and to console
by Anonymous Monk on Aug 02, 2009 at 15:34 UTC
Re^5: Print STDOUT and STDERR to file and to console
by Anonymous Monk on Aug 02, 2009 at 07:28 UTC
    There is no other simple way?

    Why?

      What do tou mean why?
        Why ask There is no other simple way? Use IO::Tee if it works, seems simple :)