win32- system call - getting results back into python

Discussion in 'Python' started by gregpinero@gmail.com, May 7, 2005.

  1. Guest

    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

    >> I get blank


    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
    , May 7, 2005
    #1
    1. Advertising

  2. runes Guest

    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()
    runes, May 7, 2005
    #2
    1. Advertising

  3. Peter Hansen Guest

    wrote:
    > 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
    Peter Hansen, May 7, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page