Issue 1328851: pclose raises spurious exception on win32 (original) (raw)
When a program's exit status is -1, the Windows-specific _PyPclose() function will return -1, which is mistaken by its caller file_close() as a request to raise an exception, which then becomes IOError with errno set to zero.
My proposed fix is to change
result = exit_code;
into
result = exit_code & 0xffff;
which should do the right thing at least on win32 (I don't care about win16).
Patch attached. (I'd check this in but I can't test it.)
To reproduce:
(1) On XP, in the control panel, stop the "Server" service.
(2) Run the following code:
import os p = os.popen("net share <nul:") print p.read() p.close()
Notice how the p.close() call raises an IOError: (0, 'Error')
Here's some other quick tests for posterity:
TEST 1 [from a downloaded msi from a while ago]
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
import os p = os.popen("net share <nul:") print p.read() The Server service is not started.
Is it OK to start it? (Y/N) [Y]:
p.close() Traceback (most recent call last): File "", line 1, in IOError: [Errno 0] Error
TEST 2
Python 3.0a2 (py3k:59579M, Dec 20 2007, 08:46:46) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
import os p = os.popen("net share <nul:") print(p.read()) No valid response was provided. The Server service is not started.
Is it OK to start it? (Y/N) [Y]:
p.close() -256