Re: Return Value from Background System Call
- From: Sherm Pendley <spamtrap@xxxxxxxxxxx>
- Date: Mon, 04 Dec 2006 13:02:47 -0500
Ben Morrow <benmorrow@xxxxxxxxxxxxx> writes:
Quoth Sherm Pendley <spamtrap@xxxxxxxxxxx>:
The meaning of a 0 exit status has to be interpreted in the context of the
launched app. For many apps, a 0 exit status is used to indicate failure of
a different sort than a general failure to execute the app,
I think you are getting confused here. A 0 exit status indicates
success...
No, it means that either main() ended in return 0, or exit(0) was called else-
where in the child app. The meaning of a particular value varies from app to
app and has not been standardized.
gcc only exits with 0 if it was successful.
OK, I stand corrected. A bogus example doesn't change my point though - a
value of 0 returned from system() does not necessarily indicate no errors from
the child. It indicates that the child returned 0, and the meaning of that 0
can vary.
Also keep in mind that the exit status of a program is whatever value is
returned from exit() or main(). Since you're launching this app in the
background and it's still running, that's probably why you're getting all
zeroes - you can't get an exit status from an app until it actually exits.
Please read the docs for the functions you are talking about. system
does not return until the command has exitted. Adding an & doesn't
change that.
I *have* read those docs, many times over the past ten years. I read them
again before posting. I meant to say the same thing you said, although I
didn't express it nearly so well. The "so what you're getting is the exit
status of the shell that launched your background app" at the end of the
quoted paragraph is implicit; I should have spelled it out to avoid this
confusion.
However, it *does* make system execute the command via a
shell instead of directly, and it is the shell which is exitting with 0,
One-argument system() will *always* execute its command via a shell. To
bypass shell command parsing and execute a program directly, one uses the
multi-argument form of system().
What the & at the end of the command does is change how the called shell
behaves. Instead of waiting for the command to finish and propagating its
exit status upward, the shell returns 0 immediately to indicate that the
command was successfully launched in the background.
I would advise the OP to fork/exec manually in Perl, as then you can see
what is actually happening.
Good advice.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
.
- Follow-Ups:
- Re: Return Value from Background System Call
- From: Martijn Lievaart
- Re: Return Value from Background System Call
- References:
- Return Value from Background System Call
- From: goodcall1
- Re: Return Value from Background System Call
- From: Sherm Pendley
- Re: Return Value from Background System Call
- From: goodcall1
- Re: Return Value from Background System Call
- From: Sherm Pendley
- Return Value from Background System Call
- Prev by Date: Re: Comparing hash tables
- Next by Date: two axis, two data sets GD::Graphic
- Previous by thread: Re: Return Value from Background System Call
- Next by thread: Re: Return Value from Background System Call
- Index(es):
Relevant Pages
|