Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: os.system error returns Date: Fri, 12 Jun 2015 13:48:40 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 28 Message-ID: References: NNTP-Posting-Host: 67-130-15-94.dia.static.qwest.net X-Trace: reader1.panix.com 1434116920 11449 67.130.15.94 (12 Jun 2015 13:48:40 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Fri, 12 Jun 2015 13:48:40 +0000 (UTC) User-Agent: slrn/1.0.2 (Linux) Xref: csiph.com comp.lang.python:92521 On 2015-06-12, 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. 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??? gmail.com