Connecting Tech Pros Worldwide Forums | Help | Site Map

POSIX system() call return value

jensthiede@gmail.com
Guest
 
Posts: n/a
#1: Oct 23 '06
My question is simple, but I guess the answer isn't. Why does the
system() function on a POSIX system return the exit status of the
called command as 2^8*n instead of n?

Any good replies much appreciated,

Jens Thiede.


Igmar Palsenberg
Guest
 
Posts: n/a
#2: Oct 23 '06

re: POSIX system() call return value


jensthiede@gmail.com wrote:
Quote:
My question is simple, but I guess the answer isn't. Why does the
system() function on a POSIX system return the exit status of the
called command as 2^8*n instead of n?
Because system() itself might fail, and if the exit status of the called
command was n, there is no way of knowing if system() has failed, of the
called command.



Igmar
jensthiede@gmail.com
Guest
 
Posts: n/a
#3: Oct 23 '06

re: POSIX system() call return value



Igmar Palsenberg wrote:
Quote:
jensthiede@gmail.com wrote:
Quote:
My question is simple, but I guess the answer isn't. Why does the
system() function on a POSIX system return the exit status of the
called command as 2^8*n instead of n?
>
Because system() itself might fail, and if the exit status of the called
command was n, there is no way of knowing if system() has failed, of the
called command.
>
>
>
Igmar
Thanks, that makes sense.

Jens.

Kenneth Brody
Guest
 
Posts: n/a
#4: Oct 23 '06

re: POSIX system() call return value


Igmar Palsenberg wrote:
Quote:
>
jensthiede@gmail.com wrote:
Quote:
My question is simple, but I guess the answer isn't. Why does the
system() function on a POSIX system return the exit status of the
called command as 2^8*n instead of n?
>
Because system() itself might fail, and if the exit status of the called
command was n, there is no way of knowing if system() has failed, of the
called command.
Which is why, if you check your system's documentation, you will
probably see it tell you which macros to use to decode the value.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@gmail.com>

Keith Thompson
Guest
 
Posts: n/a
#5: Oct 23 '06

re: POSIX system() call return value


jensthiede@gmail.com writes:
Quote:
My question is simple, but I guess the answer isn't. Why does the
system() function on a POSIX system return the exit status of the
called command as 2^8*n instead of n?
>
Any good replies much appreciated,
The C standard says only:

If the argument is a null pointer, the system function returns
nonzero only if a command processor is available. If the argument
is not a null pointer, and the system function does return, it
returns an implementation-defined value.

If you have specific questions about POSIX (which is not part of the C
standard), try comp.unix.programmer -- or consult the documentation
for your system.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Closed Thread