This is related to my earlier post,
Teeing STDOUT and STDERR to files using filehandle references, from about a month ago.
I'm redirecting STDOUT and STDERR to files with code similar (but with more function calls in the way) to this:
$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'};
Later, I try to restore STDOUT and STDERR before I close the logfiles:
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'});
}
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:
print() on closed filehandle main::STDOUT at FSLAMTest.pm line 312.
It would seem that my attempt to preserve the original STDOUT and STDERR is not successful. Any suggestions? TIA.
--isotope
http://www.skylab.org/~isotope/
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.