user915783
user915783

Reputation: 699

svn command line not working from Python

I run following svn command successfully on cmd.exe(Win 7):

svn info "svn://azsvn/..some path"

however, running the following through Python as:

path = 'svn://azsvn/..some path'
cmd_str = 'svn info ' + path
proc = subprocess.Popen(cmd_string, shell=True)
out, err = proc.communicate()

returns empty. What I am doing wrong?

sedy

Upvotes: 0

Views: 485

Answers (2)

Laurent H.
Laurent H.

Reputation: 6526

You just need to set stdout and stderr to PIPE, like this:

   proc = subprocess.Popen(cmd_string, shell=True,
                           stdout=subprocess.PIPE, stderr= subprocess.PIPE)

In this way the communicate() method will return the expected tuple.

Upvotes: 1

Edwin Buck
Edwin Buck

Reputation: 70909

I imagine that when you are running the command from the shell, the shell is stripping off the quotes on "pth" and passing in the shell-processed command

 svn info pth

But when you are using the API library, they are attempting to honor the command as closely as possible to the parameters you pass into the library, so when it gets executed it runs something like

 svn info "pth"

In the actual SVN processor. This likely has the issue of SVN not knowing a file like "pth" and failing.

I'd try a cmd_str of svn info pth an see if I achieved the desired results. In addition, you might find that running a command in the shell of svn info \"pth\" might fail in a manner similar to your Python launch.

Upvotes: 0

Related Questions