POSIX system() call return value

Discussion in 'C Programming' started by jensthiede@gmail.com, Oct 23, 2006.

  1. Guest

    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.
     
    , Oct 23, 2006
    #1
    1. Advertising

  2. 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
     
    Igmar Palsenberg, Oct 23, 2006
    #2
    1. Advertising

  3. Guest

    Igmar Palsenberg wrote:
    > 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.
     
    , Oct 23, 2006
    #3
  4. Igmar Palsenberg wrote:
    >
    > 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: <mailto:>
     
    Kenneth Brody, Oct 23, 2006
    #4
  5. 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) <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.
     
    Keith Thompson, Oct 23, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Scott Williams

    Strange return value from os.system(...) call

    David Scott Williams, Oct 13, 2004, in forum: Python
    Replies:
    1
    Views:
    1,806
    Michael Fuhr
    Oct 13, 2004
  2. M.N.A.Smadi

    Posix return or exit

    M.N.A.Smadi, Oct 5, 2005, in forum: Python
    Replies:
    1
    Views:
    357
    Sybren Stuvel
    Oct 5, 2005
  3. Greenhorn
    Replies:
    15
    Views:
    840
    Keith Thompson
    Mar 6, 2005
  4. Raymond O'Connor
    Replies:
    1
    Views:
    149
    Raymond O'Connor
    Mar 8, 2007
  5. Venks
    Replies:
    10
    Views:
    231
    MonkeeSage
    Dec 7, 2007
Loading...

Share This Page