G
Greg Hurrell
So I wanted to know why the global variable $? wasn't being set to
reflect the exit status of the subprocess when using popen3; I checked
the list archives and saw that this has come up many times and that
the cause is that popen3 forks a child, then from the child forks
another, effectively a "grandchild" process.
One of the consequences is that the exit status is effectively thrown
away. The workarounds suggested in the archives are:
- don't use popen3; find an alternative
- instead of checking $? make sure that nothing is printed to the
standard err
- append the exit code to the standard error as the last line and
extract it later
- write a popen3 replacement that uses a child rather than a
grandchild
So I've tried the latter option but I'm still left with the
curiosity... why does popen3 use this child/grandchild model? What are
the advantages of it?
Cheers,
Greg
reflect the exit status of the subprocess when using popen3; I checked
the list archives and saw that this has come up many times and that
the cause is that popen3 forks a child, then from the child forks
another, effectively a "grandchild" process.
One of the consequences is that the exit status is effectively thrown
away. The workarounds suggested in the archives are:
- don't use popen3; find an alternative
- instead of checking $? make sure that nothing is printed to the
standard err
- append the exit code to the standard error as the last line and
extract it later
- write a popen3 replacement that uses a child rather than a
grandchild
So I've tried the latter option but I'm still left with the
curiosity... why does popen3 use this child/grandchild model? What are
the advantages of it?
Cheers,
Greg