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:
Aaron Crane
Date:
February 6, 2013 19:08
Subject:
Re: [perl #116659] closing STDIN causes warning when openingunrelated file
Message ID:
CACmk_tu5KQyZf99m-njd4Mgpb34tka+aCYTX_=ffYrOJXSbxOQ@mail.gmail.com
David Golden <xdg@xdg.me> wrote:
> If you close STDIN and then your
> program requires a module, the handle for loading it will wind up on
> fd 0, too.
>
> Capture::Tiny goes through some hoops to avoid that, but it would be
> nice if the core could find a way to stay off fd 0 (assuming a
> sufficiently portable way to do so exists).

For Unixish systems, I think the approach would be to look at the fd
returned by open() (or pipe(), or socket(), or what-have-you), and
while it's one of 0,1,2, dup() it; then close() the original fd, and
any others that were in the bad range.  (That's portable back to
Seventh Edition, and probably earlier.)

I don't know what hoops Capture::Tiny jumps through in this case, but
AFAICT, that logic should work in Perl space just as well as in C
space.

I'm afraid I have no idea what that would do on Win32 or VMS, or if
the question's even meaningful there.  Anyone else?

-- 
Aaron Crane ** http://aaroncrane.co.uk/

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