POSIX system() call return value

J

jensthiede

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.
 
I

Igmar Palsenberg

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
 
J

jensthiede

Igmar said:
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.
 
K

Kenneth Brody

Igmar said:
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:[email protected]>
 
K

Keith Thompson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top