473,511 Members | 15,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2289
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6643
by: Eric Ching | last post by:
Can I run pythonw with a script that takes command line arguments then launches a GUI? I try pythonw myscript.pyw -option arg (etc.) and nothing happens. Nothing, as in I am immediately returned...
3
2166
by: vm_usenet | last post by:
Hi everyone, I've seen this subject come up in another thread, but not getting enough attention - so I'll just ask it: When running python code via pythonw, what exactly happens to stderr? I...
1
2947
by: Jo Schambach | last post by:
I wrote a python GUI with tkInter and installed it on a windows machine with the .pyw extension, so it will be executed from pythonw.exe instead of python.exe, since I didn't want the console...
3
5492
by: Darren Dale | last post by:
I'm a developer on the matplotlib project, and I am having trouble with the subprocess module on windows (Python 2.4.2 on winXP). No trouble to report with linux. I need to use _subprocess instead...
5
2350
by: Ron Garret | last post by:
I'm trying to run the Python examples distributed with XCode and they all give me the same error: Traceback (most recent call last): File "checktext.py", line 35, in <module> main() File...
9
6457
by: Phoe6 | last post by:
Hi all, Consider this scenario, where in I need to use subprocess to execute a command like 'ping 127.0.0.1' which will have a continuous non- terminating output in Linux. # code # This...
10
2555
by: JD | last post by:
Hi, I want send my jobs over a whole bunch of machines (using ssh). The jobs will need to be run in the following pattern: (Machine A) (Machine B) (Machine C) Job A1 Job B1 ...
12
4509
by: bhunter | last post by:
Hi, I've used subprocess with 2.4 several times to execute a process, wait for it to finish, and then look at its output. Now I want to spawn the process separately, later check to see if it's...
3
40276
by: John Velman | last post by:
New to mac. I have leopard. What's the difference between python and pythonw? So far (which isn't very far) I can't tell the difference. I have a small application using TKinter that I was...
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5676
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.