os.system error returns

Peter Otten __peter__ at web.de
Fri Jun 12 09:52:01 EDT 2015


Grawburg wrote:

> I have a piece of code written for a Raspberry Pi with no explanation for
> two of the lines -- and I can't find an explanation I understand.
> 
> Here are the lines:
> if os.system('modprobe --first-time -q w1_gpio') ==0
> 
> if os.system('modprobe -q w1_gpio') == 256:
> 
> 
> 
> I know what the 'modprobe...' is, it's the 0 and the 256 I don't get.
> Where do these numbers come from? I recognize they're some kind of error
> returns, but don't know what they mean.

By convention a return value of 0 means that the invoked program terminated 
normally, non-zero returns indicate an error. For the details you have to 
look into the modprobe documentation.

The invoked program is free to return a value in the range 0...255 which 
then goes into the upper byte of the return value of os.system(). For 
example let's use python instead of modprobe:

>>> os.system("python -c 'exit(42)'")
10752

You don't recognize the 42? Then how about

>>> os.system("python -c 'exit(42)'") >> 8
42

Read

https://docs.python.org/2.7/library/os.html#os.system

for the details.




More information about the Python-list mailing list