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

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.

Replies are listed 'Best First'.
Re^9: Print STDOUT and STDERR to file and to console
by Your Mother (Archbishop) on Aug 02, 2009 at 17:49 UTC
    I can’t use external modules by definition

    As ikegami was demonstrating, there is no difference whatsoever between pasting in code from one of us and pasting in code from one of us that uploaded it to the CPAN. Functionally, ethically, legally. In fact the CPAN code is safer legally because it has an explicit license. If you use code from here without specifically getting permission from the author (or from one of the members who explicitly lists the license under which she or he posts) you could theoretically run into a legal dispute. The CPAN code is probably safer functionally as it is much more likely to be tested and vetted.

Re^9: Print STDOUT and STDERR to file and to console
by Anonymous Monk on Aug 03, 2009 at 04:04 UTC
    As I wrote – I can’t use external modules by definition.

    If you can use code one of us would offer, you can use external modules, even if you have to copy/paste the code.