Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Why doesn't open() return an error when a pipe open fails?

by faq_monk (Initiate)
on Oct 08, 1999 at 00:29 UTC ( #731=perlfaq nodetype: print w/ replies, xml ) Need Help??

Current Perl documentation can be found at perldoc.perl.org.

Here is our local, out-dated (pre-5.6) version:

It does, but probably not how you expect it to. On systems that follow the standard fork()/exec() paradigm (such as Unix), it works like this: open() causes a fork(). In the parent, open() returns with the process ID of the child. The child exec()s the command to be piped to/from. The parent can't know whether the exec() was successful or not - all it can return is whether the fork() succeeded or not. To find out if the command succeeded, you have to catch SIGCHLD and wait() to get the exit status. You should also catch SIGPIPE if you're writing to the child -- you may not have found out the exec() failed by the time you write. This is documented in the perlipc manpage.

On systems that follow the spawn() paradigm, open() might do what you expect - unless perl uses a shell to start your command. In this case the fork()/exec() description still applies.

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (11)
As of 2014-11-22 18:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (123 votes), past polls