[Tutor] Process control and capturing output

Connor.Smith@huntington.com Connor.Smith at huntington.com
Wed Jun 1 21:16:36 CEST 2005


Hi there - 

I'm trying to capture the output of a long-running command in the 
background (it's a CVS rdiff on a fairly big repository).  I need to 
capture the stdout from this command, and then parse it later for a report

Defining the function:

def rdiffApp (targetModule, buildFromStamp, buildToStamp = "HEAD"):
 
        command = "cvs rdiff -s -r \"%(buildFromStamp)s\" -r 
\"%(buildToStamp)s\" %(targetModule)s" % locals()
 
        print "Running CVS Command:"
        print command
 
        try:
                cvsrdiffoutfile, cvsstdinfile = popen2.popen2(command)
        except os.error:
                print "CVS command failed at OS level."
                print "Rdiff operation did not complete"
                print "Bailing..."
                sys.exit(1)
        except:
                print "Unknown error occurred."
                print "Rdiff operation did not complete."
                print "Bailing..."
                sys.exit(2)
 
        #And return with anything we found in here
 
        cvsrdiffout = cvsrdiffoutfile.readlines()
        return cvsrdiffout


And then running the following line:

cvs = rdiffApp("MODULE_NAME", "TAG")

never returns.  In fact, it hangs the interpreter, and I have to kill the 
window to try again. 

I'm running Python 2.4 on a Windows 2000 box.  It looks like popen2 isn't 
waiting for the command to complete, and I don't know how to make it do 
that.  An easy solution to this would be to write the stdout file to disk, 
and then read it later, but I'd rather not write temp files to disk, if I 
can keep them in a file-like object in memory.  Any help?  Thanks in 
advance,

-Cs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050601/071b432b/attachment.htm


More information about the Tutor mailing list