subprocess escaping POpen?!
Chris Withers
chris at simplistix.co.uk
Thu Aug 5 07:16:33 EDT 2010
Hi All,
I have a script that does the following:
from subprocess import Popen,PIPE,STDOUT
def execute(command,cwd):
return Popen(
command,
stderr=STDOUT,
stdout=PIPE,
universal_newlines=True,
cwd=cwd,
shell=True,
).communicate()[0]
captured = execute('svn up .')
Now, if the subversion update requires authentication credentials, it
manages to write to the console running the above script, *and* read
input from it too.
This is a bit baffling to me, I thought Popen.communicate() was happily
hoovering all the output to stdout and stderr into the result returned
from communicate?
And, indeed, if I change the script instead to do:
import sys
f = open('test.py','w')
f.write('import sys; sys.stderr.write("Hello!\\n")')
f.close()
captured = execute('test.py')
...then the output is indeed captured. So, what is svn doing
differently? How is it escaping its jail?
Chris
More information about the Python-list
mailing list