On Sat, Dec 15, 2001 at 12:19:03AM +0900, nobu.nokada / softhome.net wrote:
> Ignoring the child died, the parent process goes on. Of
> course, reading from the IO returns nil and writing causes an
> exception Errno::EPIPE, however, there's no way for the parent
> to know whether the child died before exec or successfully
> exec'ed and the command exited.
No, but you can make a good guess. Most programs return an error code
of 1 or 2 on error (unless they died via a signal, and I'm not sure if
there's a standard error code for that case). According to the pclose
man page (Linux):
The pclose function waits for the associated process to terminate
and returns the exit status of the command as returned by wait4
...
Failure to execute the shell is indistinguishable from the
shell's failure to execute command, or an immediate exit of the
command. The only hint is an exit status of 127.
So if it were possible to call pclose, then it would be possible to
guess whether the program ran successfully or not (though I'm not sure
whether this is a portable solution...).
Unfortunately, the only place that Ruby ever calls pclose is from
pipe_finalize. Writing a wrapper for pclose should be trivial; just
don't forget to set fptr->f and fptr->f2 to NULL.
Paul