subprocess escaping POpen?!


C

Chris Withers

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
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top