From: Chris Withers on
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

From: Chris Withers on
Wolfgang Rohdewald wrote:
> On Donnerstag 05 August 2010, Chris Withers wrote:
>> ...then the output is indeed captured. So, what is svn doing
>> differently? How is it escaping its jail?
>
> maybe it does not read from stdin but directly from /dev/tty

But why only the request for auth credentials?

Chris

From: Wolfgang Rohdewald on
On Donnerstag 05 August 2010, Chris Withers wrote:
> ...then the output is indeed captured. So, what is svn doing
> differently? How is it escaping its jail?

maybe it does not read from stdin but directly from /dev/tty


--
Wolfgang
From: Jean-Michel Pichavant on
Chris Withers wrote:
> 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
>
You did not redirect stdin, so it is expected you can still read input
from the console. And it looks like svn is writting the credentials
prompt on stderr.

You may want to look at http://pysvn.tigris.org/docs/pysvn.html though.

JM


From: Chris Withers on
Jean-Michel Pichavant wrote:
> You did not redirect stdin, so it is expected you can still read input
> from the console.

Okay, so if I definitely wanted no input, what should I pass as the
stdin parameter to the POpen constructor?

> And it looks like svn is writting the credentials
> prompt on stderr.

....which, as you can see from the code I posted, is piped to STDOUT,
which is then PIPE'd through to the calling python so that
communicate()'s return value will contain the output.

As I explained, I can't reproduce this by replacing svn with a simple
python script that writes to stderr. So, what is svn doing?

> You may want to look at http://pysvn.tigris.org/docs/pysvn.html though.

Yeah, we were using that, but found it excruciatingly painful due to its
dependency on a subversion source install due to its c extension.

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk