By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,701 Members | 1,928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,701 IT Pros & Developers. It's quick & easy.

BUG pythonw vs subprocess

P: n/a
There seems to be a problem with calling subprocesses from a script run
with pythonw rather than python. The error doesn't seem to be a function
of using pythonw.exe rather than python.exe in the Popen call, but we
seem to get an error when pythonw is used to execute the script proc0.py

C:\Tmp>cat proc0.py
#proc0.py
import sys
from subprocess import Popen, PIPE
sys.stderr = sys.stdout = open('out.txt','w')
job = Popen('pythonw.exe -u proc1.py',stdout=PIPE,stderr=PIPE)
print 'pid',job.pid
out,err=job.communicate()
print 'out', out
print 'err', err
#end of proc0.py

C:\Tmp>cat proc1.py
#proc1.py
import sys, os
print 'sys.executable', sys.executable
print 'sys.argv', sys.argv
print 'stdout IN THE CHILD', os.getpid()
print >>sys.stderr, 'stderr IN THE CHILD', os.getpid()
#end of proc1

C:\Tmp>python proc0.py

C:\Tmp>cat out.txt
pid 1156
out sys.executable c:\python\pythonw.exe
sys.argv ['proc1.py']
stdout IN THE CHILD 1156

err stderr IN THE CHILD 1156
C:\Tmp>pythonw proc0.py

C:\Tmp>cat out.txt
Traceback (most recent call last):
File "proc0.py", line 5, in ?
job = Popen('pythonw.exe -u proc1.py',stdout=PIPE,stderr=PIPE)
File "c:\python\lib\subprocess.py", line 549, in __init__
(p2cread, p2cwrite,
File "c:\python\lib\subprocess.py", line 609, in _get_handles
p2cread = self._make_inheritable(p2cread)
File "c:\python\lib\subprocess.py", line 650, in _make_inheritable
DUPLICATE_SAME_ACCESS)
WindowsError: [Errno 6] The handle is invalid

C:\Tmp>
--
Robin Becker
Jul 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
I thought pythonw didn't provide a console and so it could be that
stdin and stdout aren't connected to anything. Popen therefore doesn't
make sense. You have to use sockets or something.
Jul 19 '05 #2

P: n/a
Paul Rubin <http://ph****@NOSPAM.invalid> wrote:

I thought pythonw didn't provide a console and so it could be that
stdin and stdout aren't connected to anything. Popen therefore doesn't
make sense. You have to use sockets or something.


Exactly right. The error message is quite accurate: non-console Win32 apps
don't have stdin and stdout. The handles are invalid.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 19 '05 #3

P: n/a
Paul Rubin <http://ph****@NOSPAM.invalid> writes:
I thought pythonw didn't provide a console and so it could be that
stdin and stdout aren't connected to anything. Popen therefore doesn't
make sense. You have to use sockets or something.


Yeah... I don't know about module subprocess, but I recall there's a
known bug where pythonw actually crashes on win9x when you write to
sys.stdout, since it's not connected to anything...
John
Jul 19 '05 #4

P: n/a
John J. Lee wrote:
Paul Rubin <http://ph****@NOSPAM.invalid> writes:

I thought pythonw didn't provide a console and so it could be that
stdin and stdout aren't connected to anything. Popen therefore doesn't
make sense. You have to use sockets or something.

Yeah... I don't know about module subprocess, but I recall there's a
known bug where pythonw actually crashes on win9x when you write to
sys.stdout, since it's not connected to anything...
John

So then it's not possible to get pythonw apps eg tkinter guis to use
subprocess properly? Seems a bit daft to me.

--
Robin Becker
Jul 19 '05 #5

P: n/a
Paul Rubin wrote:
I thought pythonw didn't provide a console and so it could be that
stdin and stdout aren't connected to anything. Popen therefore doesn't
make sense. You have to use sockets or something.


Well my example is explicitly using PIPE for stderr & stdin, but I don't know
how to tell it to ignore stdin. The value None seems to be used to signal that
the existing stdin is used and that fails. I believe the solution is just to use
PIPE for stdin as well and then I don't have to write to it.
--
Robin Becker

Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.