472,127 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

BUG pythonw vs subprocess

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
5 2193
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
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
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
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
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.

Similar topics

3 posts views Thread by vm_usenet | last post: by
1 post views Thread by Jo Schambach | last post: by
3 posts views Thread by Darren Dale | last post: by
5 posts views Thread by Ron Garret | last post: by
9 posts views Thread by Phoe6 | last post: by
10 posts views Thread by JD | last post: by
12 posts views Thread by bhunter | last post: by
3 posts views Thread by John Velman | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.