This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pclose raises spurious exception on win32
Type: Stage:
Components: Windows Versions: Python 2.3
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: JosephArmbruster, amaury.forgeotdarc, gvanrossum
Priority: normal Keywords: patch

Created on 2005-10-17 18:09 by gvanrossum, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pclosefix.txt gvanrossum, 2005-10-17 18:09 context diff
Messages (3)
msg48875 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2005-10-17 18:09
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')
msg58893 - (view) Author: Joseph Armbruster (JosephArmbruster) Date: 2007-12-20 15:44
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 "<stdin>", line 1, in <module>
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
msg75769 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-11-11 23:26
The subprocess module does return the correct exit code.
It should be used instead.
History
Date User Action Args
2022-04-11 14:56:13adminsetgithub: 42494
2008-11-11 23:26:22amaury.forgeotdarcsetstatus: open -> closed
nosy: + amaury.forgeotdarc
resolution: wont fix
messages: + msg75769
2007-12-20 15:44:24JosephArmbrustersetnosy: + JosephArmbruster
messages: + msg58893
2005-10-17 18:09:52gvanrossumcreate