<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Python  has some quirks.<div><div><div><br></div></div><div>Anyway, here's the bug I've just wasted an hour on...</div><div><br></div><div>I have a shell script, which error checked the return of a Python script.</div><div><br></div><div>The python script autogens an example written in python</div><div>that automatically creates an output 3d object to be used by my</div><div>documentation web page.</div><div><br></div><div>In other words, the shell invokes python, which generates a python program,</div><div>which it then runs.  Error status were being pass as appropriate.</div><div>However, I had a syntax error.</div><div>The shell script claims it got 0.</div><div>Python claimed it was sending 256.</div><div><br></div>It turns out that the sys.exit function recommends sticking to 0-127.<br clear="all"><div><br></div><div>The irony is that Python itself was generating the 256 exit status, which it cannot handle.</div><div><br></div><div>Try these:</div><div><div>(piecad) brian@george:~/work/piecad$ python -c "import sys; sys.exit(256)"</div><div>(piecad) brian@george:~/work/piecad$ echo $?</div><div>0</div><div>(piecad) brian@george:~/work/piecad$ python -c "import sys; sys.exit(255)"</div><div>(piecad) brian@george:~/work/piecad$ echo $?</div><div>255</div></div><div><br></div><div>Bash seems to be limited to 0-255, which is what man 3 exit says should be the range.</div><div><br></div><div>But the plot thickens... the real culprit was the os.system function.</div><div>Which does return the exit status, but as the second byte of the returned 16-bit</div><div>integer. </div><div>So essentially, python returned a 1 status for the syntax error,</div><div>which o.system intentionally made into 256. Which the shell then translated to 0.</div><div><br></div><div>Whose fault is it?  Well, me of course. I should have read the 4 pages of documentation</div><div>it took to figure out what was going on! :-)</div><div><br></div><div>--<br></div><div dir="ltr" class="gmail_signature"><br><div>Brian</div><div><br></div></div></div></div></div></div></div>