good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: "close" failingby jdhedden (Deacon) |
on May 31, 2006 at 16:00 UTC ( [id://552844]=note: print w/replies, xml ) | Need Help?? |
The close command returns the exit status of the piped command.
If the piped command has exited with status=0 before close is called, then close will succeed. If it exits with status != 0 before close is called, then close will fail and $? will equal the exit status. If close is called before the piped command exits, then close will fail and $? will equal SIGPIPE. Why? Because Perl sends SIGPIPE to the piped command, then waits for it to exit, and then grabs its exit status which is the signal caught by the piped command (i.e., SIGPIPE). (Note that it is possible for the piped command to intercept the SIGPIPE signal and exit with some other exit status (e.g., exit 0) which will be picked up instead.) In the case you experienced with the web server, it may be that the CGI is getting to the close command before the piped command actually exits. If you insist on testing the status of the close command, then modify your piped command to intercept SIGPIPE and terminate with a 0 exit status. Remember: There's always one more bug.
In Section
Seekers of Perl Wisdom
|
|