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

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

Thread Previous | Thread Next
Aaron Crane
February 6, 2013 19:08
Re: [perl #116659] closing STDIN causes warning when openingunrelated file
Message ID:
David Golden <> 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

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 **

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