Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > POSIX system() call return value

Reply
Thread Tools

POSIX system() call return value

 
 
jensthiede@gmail.com
Guest
Posts: n/a
 
      10-23-2006
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.

 
Reply With Quote
 
 
 
 
Igmar Palsenberg
Guest
Posts: n/a
 
      10-23-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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
 
Reply With Quote
 
 
 
 
jensthiede@gmail.com
Guest
Posts: n/a
 
      10-23-2006

Igmar Palsenberg wrote:
> (E-Mail Removed) wrote:
> > 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.

 
Reply With Quote
 
Kenneth Brody
Guest
Posts: n/a
 
      10-23-2006
Igmar Palsenberg wrote:
>
> (E-Mail Removed) wrote:
> > 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: <(E-Mail Removed)>

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-23-2006
(E-Mail Removed) writes:
> 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) (E-Mail Removed) <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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Posix call (execve) breaks mercurial? Wayne Werner Python 0 10-11-2012 11:10 PM
Capturing STDOUT from a system call (POSIX) into an array Venks Ruby 10 12-07-2007 01:01 AM
Mocha raise exception first call, return value second call Raymond O'Connor Ruby 1 03-08-2007 08:38 AM
Posix return or exit M.N.A.Smadi Python 1 10-05-2005 04:50 PM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM



Advertisments