R
Robin Becker
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>
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>