close STDERR considered puzzling

  • Thread starter Ilya Zakharevich
  • Start date
I

Ilya Zakharevich

perl -wle "close STDERR; open F, q(>), q(/dev/tty) or print 11;
print fileno F; warn 22; print STDERR 33; print $x+77"

Try to guess the output (use /dev/con on DOSISH, ' otherwise). Solution below:
 
I

Ilya Zakharevich

If (the Perl-level) STDERR is currently closed, warn will write its
output to (the C-level) stderr, which means fd 2.

It is THIS behaviour which causes unexpected results. Is it
documented anywhere?
As a rule you should never close STD{IN,OUT,ERR}. If you must, reopen
them to or from File::Spec->devnull.

I MUST close them (in all possible combinations) to find bugs in some
UNRELATEDLY obscure ;-) part of perl. And inspecting the output leads to
some deep surprises...

Thanks,
Ilya
 
I

Ilya Zakharevich

I don't know. I don't think so.

Which does not make the behaviour less puzzling...

[ I note that I have seen this behaviour explicitly mentioned on p5p
in 90s. But at that time I did not realize how puzzling this
behaviour may be. ]

BTW, is there any backdoor way to redirect STDERR to some other fd
than 2?

Thanks again,
Ilya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top