'bye sys world\ stat pipe close(stat hex(stat' stat > returns exit code extract status from bitmask on unix-likes pipe os popen('python testexit_os py'stat pipe close(statstat > ( this code works the same under cygwin python on windows when using os popen on such unix-like platformsfor reasons we won' go into herethe exit status is actually packed into specific bit positions of the return valueit' really therebut we need to shift the result right by eight bits to see it commands run with os system send their statuses back directly through the python library callstat os system('python testexit_sys py'bye sys world statstat > ( stat os system('python testexit_os py'bye os world statstat > ( all of this code works under the standard version of python for windowstoothough exit status is not encoded in bit mask (test sys platform if your code must handle both formats) :\pp \system\exitspython os system('python testexit_sys py'bye sys world os system('python testexit_os py'bye os world pipe os popen('python testexit_sys py'pipe read('bye sys world\npipe close( os popen('python testexit_os py'close( program exits