0

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

3 Comments

Actually, when I run the above in Pycharm4.5.3, I can see command return the information expected in console window but the out and err variables read None value
Quotes and shells can be tricky. Basically you have to concede that many shells process strings before executing them, and that processing is very dependent on the positions of quotes (if they are there). APIs on the other hand, don't do what shells do, because well, they are not shells.
I have updated my question,sorry about less information before

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.