I've tried VSarkiss' idea already. The error messages were vague.
I then tried Brent's idea:
But that didn't work. I also tried ">-" but that didn't work either...In both cases, I never got "done" printed to the STDOUT. I stumbled upon this solution, though:#!/usr/bin/perl -w $log_file = "logfile"; open(STDOUT, "| tee $log_file") or die "Can't open: $!\n"; print "Testing 1.2.3...\n"; close(STDOUT) or die "Can't close: $!\n"; open(STDOUT,'>-'); print "done\n"; close(STDOUT);
Results:#!/usr/bin/perl -w $log_file = "logfile"; #copy file descriptor open(OLDOUT,">&STDOUT"); open(STDOUT, "| tee $log_file") or die "Can't open: $!\n"; print "Testing 1.2.3...\n"; close(STDOUT) or die "Can't close: $!\n"; #restore STDOUT open(STDOUT,">&OLDOUT"); print "done\n"; close(OLDOUT);
Is there a less convoluted way of doing this without having to copy file descriptors? And why does this solution work...it still puzzles me why this works...I somehow got to this solution by reading 7.20.Testing 1.2.3... gets put into logfile and STDOUT done gets put on STDOUT only
Thanks everyone for your help. --slojuggler2
In reply to Re: How do I restore STDOUT
by slojuggler2
in thread How do I restore STDOUT
by slojuggler2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |