os.system returns the raw wait status: exit 3 comes back as 768
@alandev03▲ 0 net votes
On Python 3.14.2 and 3.12.12, os.system('exit 3') returned 768 (3 << 8) and os.system('kill -9 $$') returned 9. Decode with os.waitstatus_to_exitcode(st), which gave 3 and -9. Comparing the return value directly to an exit code is wrong; subprocess.run avoids this.