`os.system` returns inconsistent exit codes
Closed this issue · 0 comments
jagmoreira commented
Problem
For a strange reason, os.system(<shell code>)
can sometimes return exit codes greater than 255, even if <shell code>
returns codes between 0 and 255, the Unix standard exit codes:
>>> import os
>>> os.system('exit 1')
256
>>> os.system('exit 25')
6400
>>> os.system('exit 255')
65280
>>> os.system('exit 256')
0
This is a problem when we are propagating the exit codes of a shell command outside of skelebot because any number greater than the Unix max is treated as modulo 256. Therefore if os.system
returns 256 this is interpreted as no error by the shell: 256 mod 256 = 0.
Solution
Replacing all os.system
calls with subprocess.call
will return the actual integer exit code of the called shell code.