I seem to have found a bug in perl's support for opening file handles to scalar variables (so-called in memory files), but I wanted to make sure I wasn't doing something stupid. Could folks try out the following test code?
The problem happens with perl 5.8.6 on MacOS X 10.4 and on Solaris 2.7. In the test code, I first open STDOUT to a variable and then open STDERR to STDOUT. All output to STDOUT makes it to the variable, but output to STDERR doesn't; that is, the test code prints out
testing stdout capture 1
testing stdout capture 2
Is this a bug in perl 5.8.6?
#!/usr/bin/perl -w
use strict;
use FileHandle;
open SAVED_STDOUT, ">&STDOUT" or die "couldn't save STDOUT: $!\n";
open SAVED_STDERR, ">&STDERR" or die "couldn't save STDERR: $!\n";
print SAVED_STDOUT ""; # to suppress warning about possible typo
my $captured_output = "";
close STDOUT;
open STDOUT, ">", \$captured_output or die "couldn't re-open STDOUT: $
+!\n";
close STDERR;
open STDERR, ">&STDOUT" or die "couldn't re-open STDERR: $!\n";
print "testing stdout capture 1\n";
print STDERR "testing stderr capture\n";
print "testing stdout capture 2\n";
close STDOUT; open STDOUT, ">&SAVED_STDOUT";
close STDERR; open STDERR, ">&SAVED_STDERR";
print STDERR $captured_output, "\n";
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.