Re: Return Value from Background System Call



goodcall1@xxxxxxxxxxx writes:

Sherm Pendley wrote:
goodcall1@xxxxxxxxxxx writes:

Problem: I am having trouble figuring out why a system call in the
background *always* returns 0. Debian Linux Perl 5.8.7

What am I trying to do: I am trying to launch a browser from a perl/Tk
button and it always returns 0 (and hence prints the failed to open
browser message)

As the docs for system() state, a return value of 0 does not indicate
failure:

perldoc -f system


That is correct - 0 should indicate success

That's not what I said, although I'll admit the difference is subtle. The
fact that 0 does not indicate failure does not necessarily imply that it
always indicates success. All it means is that the system() call itself
succeeded, and that the launched app returned a 0 exit status.

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, such as bogus
arguments or malformed input files. This allows command "chains" such as
the following:

gcc -o foo foo.c && mv ./foo /usr/local/bin/foo

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.

I beginning to wonder what the "success" indicator of 0 points to? Ok
- so I found this in the docs:

"The return value is the exit status of the program as returned by
the "wait" call. "

The last sentence of that same paragraph says:

"Return value of -1 indicates a failure to start the program (inspect
$! for the reason)."

So you can easily check to see if firefox was successfully started, by
comparing the return value of system() with -1.

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
.