icon Top 9 categories map      RocketAware > Perl >

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

Tips: Browse or Search all pages for efficient awareness of Perl functions, operators, and FAQs.


Search Perl pages


By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Integer, Floating point, Matrix, Statistics, Boolean, ...

Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...


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 (eg, 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.

Source: Perl FAQ: System Interaction
Copyright: Copyright (c) 1997 Tom Christiansen and Nathan Torkington.
Next: What's wrong with using backticks in a void context?

Previous: How can I capture STDERR from an external command?

(Corrections, notes, and links courtesy of RocketAware.com)

[Overview Topics]

Up to: Local Process Communication

Rapid-Links: Search | About | Comments | Submit Path: RocketAware > Perl > perlfaq8/Why_doesn_t_open_return_an_err.htm
RocketAware.com is a service of Mib Software
Copyright 2000, Forrest J. Cavalier III. All Rights Reserved.
We welcome submissions and comments