os.system error returns

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

os.system error returns

Grant Edwards-7
On 2015-06-12, Grawburg <grawburg at myglnc.com> 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.

In generail, Linux command line utilities return 0 to indicate
success/OK/true. They return non-zero to indicate failure/error/false.

The status you get back from os.system() on linux is a 16-bit number
with the the upper 8 bits the return value from the command and the
lower 8 bits the signal number that terminated the sub-process (0
means normal exit).

So os.system() will return 0 if the command it invoked executed
successfully and returned a 0, and os.system() returns 256 if the
command it invoked returned a 1.

Grant Edwards               grant.b.edwards        Yow! Did I say I was
                                  at               a sardine?  Or a bus???