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

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

Thread Previous | Thread Next
From:
David Golden
Date:
February 7, 2013 20:54
Subject:
Re: [perl #116659] closing STDIN causes warning when openingunrelated file
Message ID:
CAOeq1c8dWCFryykwwKzRQf6wmOHFDc+6uvuzP8J+ZHYwtq8FfQ@mail.gmail.com
On Thu, Feb 7, 2013 at 3:32 PM, Eirik Berg Hanssen
<Eirik-Berg.Hanssen@allverden.no> 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.

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

# run2.pl
use v5.10;
use strict;
use warnings;
use lib '.';

close STDIN;
open my $fh, ">", "foo.xt";
say "opened on fd " . fileno $fh;
say `/bin/cat`;

###

$ perl run2.pl
Filehandle STDIN reopened as $fh only for output at run2.pl line 8.
opened on fd 0
cat: stdin: Bad file descriptor


-- 
David Golden <xdg@xdg.me>
Take back your inbox! → http://www.bunchmail.com/
Twitter/IRC: @xdg

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About