Antw: Re: [vienna.pm] pipe or die
Roland.Bauer at mediaprint.at
Mon May 15 03:05:55 CDT 2000
* * * vienna-pm-list * * *
> Johannes Fuernkranz wrote on Thu, May 04 2000 (13:40:18 +0200):
> > open(IN,"non_existent_script |") or die "Script doesn't exist";
Ergaenzug aus dem Perl-FAQ ;-)
Why doesn't open() return an error when a pipe open fails?
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.
Taeglich eine FAQ aus dem FAQ kann man sich zumailen lassen via
This is a daily mailing from the Perl FAQ a Day website.
For subscription info, or to have your address removed from
the mailing list, please see http://yoak.com/daily_perl/
You are subscribed to vienna-pm-list as "Roland Bauer" <Roland.Bauer at mediaprint.at>
More information about the Vienna-pm