develooper Front page | perl.perl5.porters | Postings from February 2013

Re: [perl #116659] closing STDIN causes warning when openingunrelated file

Thread Previous | Thread Next
Eirik Berg Hanssen
February 7, 2013 21:22
Re: [perl #116659] closing STDIN causes warning when openingunrelated file
Message ID:
On Thu, Feb 7, 2013 at 9:54 PM, David Golden <> wrote:

> On Thu, Feb 7, 2013 at 3:32 PM, Eirik Berg Hanssen
> <> wrote:
> >   That seems like a perfectly good answer – to a different question. ;-)
> It was the answer to why we should stay of fd 0 and avoid the problem.

  Mhm.  To bad it's not easily controllable.

In answer to your question, probably because having a write-only
> handle on a descriptor that programs expect to read from makes them
> crash:

  But that's not related to the reopening.  A closed STDIN will also have
the program crashing:

eirik@bluebird[22:08:26]~$ perl -wE 'close STDIN; system "/bin/cat"; say
/bin/cat: -: Bad file descriptor
/bin/cat: closing standard input: Bad file descriptor
eirik@bluebird[22:08:34]~$ perl -wE 'close STDIN; open my $fh, ">", "test";
system "/bin/cat"; say $?;'
Filehandle STDIN reopened as $fh only for output at -e line 1.
/bin/cat: -: Bad file descriptor

  Okay, those are slightly different chrashes (for cat; I've tried a few
others, but got no difference), but I don't see how that difference has
only one of them meriting a warning.

  (Perhaps there are other instances where this difference makes a
significant difference?)

  If both should warn, the trigger should be executing a process with no
fd0 opened for reading.

  But currently, only one of them warns ... and I still cannot say I see a
reason for it.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About