New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
subprocess fails on GetStdHandle in interactive GUI #41592
Comments
Using the suprocess module from with IDLE or PyWindows, For example:
>>> import subprocess
>>> p = subprocess.Popen("dir", stdout=subprocess.PIPE)
Traceback (most recent call last):
File "<pyshell#49>", line 1, in -toplevel-
p = subprocess.Popen("dir", stdout=subprocess.PIPE)
File "C:\Python24\lib\subprocess.py", line 545, in
__init__
(p2cread, p2cwrite,
File "C:\Python24\lib\subprocess.py", line 605, in
_get_handles
p2cread = self._make_inheritable(p2cread)
File "C:\Python24\lib\subprocess.py", line 646, in
_make_inheritable
DUPLICATE_SAME_ACCESS)
TypeError: an integer is required The error originates in the mswindows implementation of I added "if not handle: return GetCurrentProcess()" to def _make_inheritable(self, handle):
..."""Return a duplicate of handle, which is inheritable"""
...if not handle: return GetCurrentProcess()
...return DuplicateHandle(GetCurrentProcess(), handle,
....................................GetCurrentProcess(),
0, 1,
....................................DUPLICATE_SAME_ACCESS) |
Logged In: YES I ran into a similar problem in Ellogon (www.ellogon.org) My current workaround is to always set all of stdin, stdout, Looking at the code, I kinda think the fix should be:: if handle is None:
return handle
return DuplicateHandle(GetCurrentProcess(), ... where if handle is None, it stays None. But I'm also |
Logged In: YES This issue was discussed on comp.lang.python[1] and Roger """ Subprocess.py should probably check the [1]http://mail.python.org/pipermail/python-list/2005-September/300744.html |
Logged In: YES On windows, this seems to work from subprocess import *
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) ....in some cases (depending on what command you are import win32con
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
creationflags=win32con.CREATE_NO_WINDOW) ...google for Microsoft Process Creation Flags for more info |
The following bugs have been marked as duplicate of this bug: 1358527 |
Some ideas of possible solutions for this bug:
Currently, I'm leaning towards solution 2), with closing the parents PIPE ends. |
File Added: 1124861.3.patch |
Please review 1124861.3.patch. |
I've applied 1124861.3.patch to both trunk (rev 53646) and the release25-maint branch (rev 53647). |
I _think_ this traceback from a program running under Pythonw 2.4.3 Enthought Edition on WinXP is caused by the same underlying bug (in this case, stdin was set to PIPE, and stdout/stderr were both left to default):
WindowsError: [Errno 6] The handle is invalid |
I found this bug via this post: And I think 2.5.1 still has this bug. I'm not familiar with Python |
I agree with Daniel, I think this bug or a variant is still present in |
Is there any chance of having this fixed for 2.5.2 ? |
I have tested this form in Python26 ,It works
>>> import subprocess
>>> p = subprocess.Popen("cmd.exe dir", stdout=subprocess.PIPE)
>>> p.communicate()
('Microsoft Windows XP [Version 5.1.2600]\r\n(C) Copyright 1985-2001 Microsoft Corp.\r\n\r\nC:\\Python26>', None) |
Still doesn't work for me with Python 2.6.5 on Windows 7 64-bit, but apparently for a different reason. |
shell vs subprocess
The problem is the default option "Shell" is "False" , you you write commands you should turn on the shell.
for example try this to show the content of directory " C:\Python26
":
>>>import subprocess
>>> p = subprocess.Popen("dir", shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> stdout,stderr=p.communicate()
>>> print stderr # if errors doe not occur ,it is empty!
|
Ah, it works now. Thanks. |
Here I get one problem need help. import subprocess It run in windows7 os MSDOS console is OK C:\> STAF local PROCESS START COMMAND python C:\>test.py WAIT STDERRTOSTDOUT RETURNSTDOUT Response {
Return Code: 1
Key : <None>
Files : [
{
Return Code: 0
Data : Traceback (most recent call last):
File "C:\test.py", line 3, in <module>
process_response = subprocess.call('netsh wlan show interface',stdout=fileID
,shell=True)
File "C:\Python27\lib\subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 672, in __init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
File "C:\Python27\lib\subprocess.py", line 784, in _get_handles
p2cread = self._make_inheritable(p2cread)
File "C:\Python27\lib\subprocess.py", line 823, in _make_inheritable
_subprocess.DUPLICATE_SAME_ACCESS)
WindowsError: [Error 6] The handle is invalid
] I just start to learn python, I dont know how to resolve, need help. |
Update, the python version is '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]' |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: