Author twhitema
Recipients trentm, twhitema
Date 2008-09-18.23:07:00
SpamBayes Score 7.29194e-13
Marked as misclassified No
Message-id <1221779222.6.0.581055626962.issue3905@psf.upfronthosting.co.za>
In-reply-to
Content
I'm getting a 'The handle is invalid' error when using subprocess.Popen
in Python 2.5 (and 2.6). If any of the stdio handles are somehow invalid
or not real io handles (fd is not 0, 1 or 2), and you are not telling
subprocess to PIPE all of the handles, then subprocess throws the
following exception.

The easiest way to reproduce this is using run PythonWin from a Windows
Command Prompt:
  C:\Python\Lib\site-packages\pythonwin\Pythonwin.exe
and then use the following 2 subprocess code lines below:

import subprocess
p = subprocess.Popen(["python", "-c", "print 32"], stdin=None,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Python26\lib\subprocess.py", line 588, in init_
    errread, errwrite) = self._get_handles(stdin, stdout, stderr)
  File "C:\Python26\lib\subprocess.py", line 703, in _get_handles
    p2cread = self._make_inheritable(p2cread)
  File "C:\Python26\lib\subprocess.py", line 748, in _make_inheritable
    DUPLICATE_SAME_ACCESS)
WindowsError: [Error 6] The handle is invalid


Specifying PIPE for all subprocess.Popen handles is the only way I've
found to get around this problem:

p = subprocess.Popen(["python", "-c", "print 32"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.stdin.close()
p.communicate()
('32\r\n', '')
History
Date User Action Args
2008-09-18 23:07:02twhitemasetrecipients: + twhitema, trentm
2008-09-18 23:07:02twhitemasetmessageid: <1221779222.6.0.581055626962.issue3905@psf.upfronthosting.co.za>
2008-09-18 23:07:01twhitemalinkissue3905 messages
2008-09-18 23:07:00twhitemacreate