Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #92522

Re: os.system error returns

From Peter Otten <__peter__@web.de>
Subject Re: os.system error returns
Date 2015-06-12 15:52 +0200
Organization None
References <2ebdfdf225c075b2f5ef350b06bc14f0@myglnc.com>
Newsgroups comp.lang.python
Message-ID <mailman.421.1434117138.13271.python-list@python.org> (permalink)

Show all headers | View raw


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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: os.system error returns Peter Otten <__peter__@web.de> - 2015-06-12 15:52 +0200

csiph-web