I am trying to understand something that I see in the perlipc documentation.
If you are writing on a trumpet, you must also capture SIGPIPE. Otherwise, think about what happens when you run the pipe to a command that does not exist: open () will most likely succeed (this only reflects the success of fork ()), but then your output will fail - spectacularly . Perl cannot know if the command worked because your command actually works in a separate process. Perhaps exec () failed. Therefore, although readers of fictitious commands return only the fast end of the file, the scripters of the fake command will cause a signal with which they should prepare. Consider:
open(FH, "|bogus") or die "can't fork: $!"; print FH "bang\n" or die "can't write: $!"; close FH or die "can't close: $!";
It will not explode until closing, and it will explode SIGPIPE. To catch it, you can use this:
$SIG{PIPE} = 'IGNORE'; open(FH, "|bogus") or die "can't fork: $!"; print FH "bang\n" or die "can't write: $!"; close FH or die "can't close: status=$?";
If I read it correctly, it says that the first version probably will not die before the final closure.
However, this does not happen in my OS X mailbox (Perl versions 5.8.9 - 5.15.9). It explodes on open
using "can not fork: There is no such file or directory", regardless of whether I have the $ SIG {PIPE} line.
What? I do not understand?
source share