Prev: FAQ 5.38 Why does Perl let me delete read-only files? Why does "-i" clobber protected files? Isn't this a bug in Perl?
Next: FAQ 5.38 Why does Perl let me delete read-only files? Why does"-i" clobber protected files? Isn't this a bug in Perl?
From: Ben Morrow on 6 Jul 2010 06:46 Quoth Ilya Zakharevich <nospam-abuse(a)ilyaz.org>: > On 2010-07-05, Ben Morrow <ben(a)morrow.me.uk> wrote: > >> > 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? > > > I don't know. I don't think so. > > Which does not make the behaviour less puzzling... Well, it's kind-of a last ditch effort to send the error message *somewhere* sensible. Perl perhaps ought to prevent you from closing these three fds altogether (or rather, implicitly reopen them to /dev/null if you close them) and make sure they stay permanently attached to their proper filehandles. > [ 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? Oh, that's easy: close STDERR; close STDIN; open STDERR, ">", "/dev/tty"; open STDIN, "<", "/dev/tty"; You now have STDIN on fd 2 and STDERR on fd 0. Since STDERR is now open, error messages will go out of fd 0. Ben |