os.system() << 8 ?

Erik Max Francis max at alcyone.com
Wed May 28 15:29:50 EDT 2003


Jacek Generowicz wrote:

> Why does os.system seem to return a value which is 256 times the
> actual
> status code returned by its argument ?

Others have pointed out where in the documentation the behavior is
documented, and how to get the exit value (os.WEXITSTATUS).  Note that
Python is just following POSIX's lead; the C system call `system'
behaves the same way (man 3 system):

RETURN VALUE
       The value returned is -1 on error (e.g. fork failed),  and
       the  return  status of the command otherwise.  This latter
       return status is  in  the  format  specified  in  wait(2).
       Thus,  the  exit  code  of  the  command will be WEXITSTA-
       TUS(status).  In case /bin/sh could not be  executed,  the
       exit status will be that of a command that does exit(127).

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ Your theory is not right; it is not even wrong.
\__/  Wolfgang Pauli




More information about the Python-list mailing list