[Tutor] monitor subprocess and get it's output during execution
Kent Johnson
kent37 at tds.net
Mon Sep 1 13:30:33 CEST 2008
On Sun, Aug 31, 2008 at 11:39 PM, 王珂 <wkgogogo at gmail.com> wrote:
> --Then I use:
> print "Download begin ..."
> p = subprocess.Popen(["robocopy.exe" +" " + "DownloadArgs"],Shell =
> True,stdout = PIPE)
> while not str(p.poll()).isdigit():
> print ">",
> time.sleep(10)
> #don't know how to grab output and display portion of it
> print "Download complete with retval (%d) "% (p.poll())
>
> This will make robocopy never terminate, and display ">>>>>>" forever.
I am not an expert in Popen, but I think in this example robocopy is
blocked trying to output. Here is how to read the robocopy output:
p = subprocess.Popen(["robocopy.exe" +" " + "DownloadArgs"],Shell =
True,stdout = PIPE)
while True:
line = p.stdout.readline()
if not line: break
print line
Kent
More information about the Tutor
mailing list