isotope has asked for the wisdom of the Perl Monks concerning the following question:
Later, I try to restore STDOUT and STDERR before I close the logfiles:$this->{'stdout_log'} = \*FH_STDOUT; # These files have already been o +pened. $this->{'stderr_log'} = \*FH_STDERR; # Save the previous filehandles for STDOUT and STDERR so we # can restore them when we're done. $this->{'_stdout'} = \*STDOUT; $this->{'_stderr'} = \*STDERR; # Set the new filehandles for STDOUT and STDERR *STDOUT = $this->{'stdout_log'}; *STDERR = $this->{'stderr_log'};
I successfully log STDOUT/ERR to a file, but when I attempt to restore them later, the if blocks evaluate, but the print statements still go to the logfiles, instead of the TTY. Following that, of course, when I close the files and attempt to print to STDOUT and STDERR, I get:if(defined($this->{'_stdout'})) { *STDOUT = $this->{'_stdout'}; print STDOUT "STDOUT restored\n"; # Filehandle explicitly specifie +d for debugging only... undef($this->{'_stdout'}); } if(defined($this->{'_stderr'})) { *STDERR = $this->{'_stderr'}; print STDERR "STDERR restored\n"; undef($this->{'_stderr'}); }
It would seem that my attempt to preserve the original STDOUT and STDERR is not successful. Any suggestions? TIA.print() on closed filehandle main::STDOUT at FSLAMTest.pm line 312.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Restoring STDOUT and STDERR after having redirected them to files
by isotope (Deacon) on Jan 13, 2001 at 00:19 UTC | |
|
Re: Restoring STDOUT and STDERR after having redirected them to files
by chipmunk (Parson) on Jan 12, 2001 at 22:46 UTC | |
by isotope (Deacon) on Jan 12, 2001 at 22:53 UTC | |
by chipmunk (Parson) on Jan 12, 2001 at 23:07 UTC |