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

There is no other simple way?

Why?

  • Comment on Re^5: Print STDOUT and STDERR to file and to console

Replies are listed 'Best First'.
Re^6: Print STDOUT and STDERR to file and to console
by Noame (Beadle) on Aug 02, 2009 at 09:14 UTC
    What do tou mean why?
      Why ask There is no other simple way? Use IO::Tee if it works, seems simple :)
        As I wrote – I can’t use external modules by definition.
        I want to print the STDOUT and STDERR to the console and log file thereat.
        Something like the code below:
        open(LOG, "> $LOG_FILE") || die "Can't redirect stdout"; open(STDERR, "> $LOG_FILE") || die "Can't dup 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; }
        The problem with the code above is that I didn’t successes to control the STDERR output Please advice.