[Python-Dev] os.popen and exit codes on windows

Mark Hammond mhammond at skippinet.com.au
Tue May 11 22:23:33 EDT 2004


I'm looking at bug 602245 - http://www.python.org/sf/602245 - and would like
some guidance.

The issue is the return-code when closing the last handle from an os.popen()
function.

In a nutshell:  On Linux, the result of closing the last handle is the
result from the wait() function.  On Windows, the result is the integer
return code, exactly as specified by the child program - however, on
Windows, when the result is -1, an error is raised (and hence the bug
referenced above)

On Linux, the value from the wait() system call is split into three parts:
mask 0xff00 is the exit status
mask 0x007f is the signal causing the exit
mask 0x0080 is the cord dumped flag in combination with a signal

As part of fixing the bug for Windows, I have 2 basic choices:
1) Fix it by masking off the high bits, thereby returning an "unsigned"
result code - preventing -1, but still returning the result exactly as
specified by the child process.
2) Fix it by changing the result to resemble the Linux behaviour.  This
would mean programs using popen() are more portable.

My problem is that (2) will change the behaviour for existing programs.
Most programs will only check for non-zero, but we can't know that for sure.

One option is to do (1) for Python 2.3, and (2) for Python 2.4.  That
doesn't sound quite right either.  If (2) is best, we could probably forget
Python 2.3 all together, as the bug is quite old.

Any thoughts?  Comments directly in the bug are probably best.

Thanks,

Mark.




More information about the Python-Dev mailing list