473,569 Members | 2,834 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',stdou t=PIPE,stderr=P IPE)
print 'pid',job.pid
out,err=job.com municate()
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\pytho nw.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',stdou t=PIPE,stderr=P IPE)
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_inhe ritable(p2cread )
File "c:\python\lib\ subprocess.py", line 650, in _make_inheritab le
DUPLICATE_SAME_ ACCESS)
WindowsError: [Errno 6] The handle is invalid

C:\Tmp>
--
Robin Becker
Jul 19 '05 #1
5 2296
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.i nvalid> 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.i nvalid> 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.i nvalid> 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
6646
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 to the DOS prompt. I just started learning Python a couple of weeks ago, so please bear with me. I have a script that(for now) uses command line...
3
2170
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 tried running code that, among else, writes to stderr - and at some point I get an IOError claiming "Bad file descriptor". Why is this happending?
1
2957
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 window to appear. My application exits with a call to sys.exit. However, when this call is executed under pythonw.exe I get an error popup window with...
3
5495
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 of pywin32, but my trouble exists with either option: import subprocess process = subprocess.Popen(, stderr=subprocess.STDOUT,...
5
2356
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 "checktext.py", line 8, in main pathname = EasyDialogs.AskFileForOpen(message='File to check end-of-lines in:') File...
9
6469
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 hangs at this point. How should I handle these kind of commands (ping 127.0.0.1) with
10
2560
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 Job C1 Job A2 Job B2 etc
12
4515
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 finished, and if it is look at its output. I may want to send a signal at some point to kill the process. This seems straightforward, but it...
3
40280
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 working on under Linux. Both python and pythonw run it, but on both it "stops responding" (pinwheel of death) when I touch the vertical scrollbar. ...
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7917
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7665
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.