My understanding was that subprocess.py was supposed to be
backwards compatible with at least Python 2.3 if not 2.2. Wanting
subprocess and backwards compatibility, I grabbed the subprocess.py
from 2.4b1, changed the import if so that win32api was used (since I
had no _subprocess library!) and found several problems, of which
this is one (one per bug report):
The following code fails when run as a program on Windows Python
2.3.
However, the exact same code works perfectly on a unix build of
Python 2.4b1 on MacOS X. It also works on Windows if I use
an interactive interpreter and type each line in by hand (skipping
some irrelevant bits).
import subprocess
def xpaget(cmd, template="ds9"):
fullCmd = '"xpaget" %s %s' % (template, cmd,)
p = subprocess.Popen(
# executable = _XPADir + "xpaget", # use if bug in
subprocess gets fixed
args = fullCmd,
shell = True,
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
cwd = _XPADir,
)
try:
p.stdin.close()
errMsg = p.stderr.read()
if errMsg:
raise RuntimeError('%r failed: %s' % (fullCmd, errMsg))
reply = p.stdin.read() # the code fails here; the next print
statement never executes
print "xpaget read %r" % reply
return reply
finally:
p.stdout.close()
p.stderr.close()
|