win32- system call - getting results back into python

G

gregpinero

Hey everyone,

I'm trying to call a system command "svnlook log \arms" from within
python and process the results. However I'm having trouble getting the
results of the command back into python. I'm using windows if that
matters.

Here's what I have so far:

os.system("svnlook") #works but doesn't give me the output from
svnlook, just the status

commands.gettegetstatusoutput("svnlook") only works in unix?

Here's my final code which really <should> work:

pipe=os.popen("svnlook log \arms") #works from console
text=pipe.read()
print text

However this works fine and gives me many lines of output:
pipe=os.popen("dir")
text=pipe.read()
print text

Any idea what I'm doing wrong? When I call my command from the command
prompt in windows I get a line of text. By the way, I tried posting
this on the subversion group but I'm thinking maybe it's a python
question, or both?

Thanks,

Greg
 
R

runes

You wil have to use r"svnlook log \arms") or "svnlook log \\arms") to
escape the "\".

Popen usually return a file-like object, so you maye to use file
methods like .read()

ex:
d = os.popen('dir /b')
print d.read()
 
P

Peter Hansen

I'm trying to call a system command "svnlook log \arms" from within
python and process the results. However I'm having trouble getting the
results of the command back into python. I'm using windows if that
matters.

As "runes" pointed out, you are getting caught by the \a escape sequence.

A better solution in this particular case is to see that the SVN
utilities all understand forward slashes just fine, so you can use
"svnlook log /arms" and it should work.

Note that there is also a Python library that wraps the SVN interface so
you could also skip the direct calls to svnlook and do this with Python
calls instead. Google for "pysvn" for more.

-Peter
 

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

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top