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


Groups > comp.lang.python > #92522 > unrolled thread

Re: os.system error returns

Started byPeter Otten <__peter__@web.de>
First post2015-06-12 15:52 +0200
Last post2015-06-12 15:52 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#92522 — Re: os.system error returns

FromPeter Otten <__peter__@web.de>
Date2015-06-12 15:52 +0200
SubjectRe: os.system error returns
Message-ID<mailman.421.1434117138.13271.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web