2008/9/1 Kent Johnson <[EMAIL PROTECTED]> > On Sun, Aug 31, 2008 at 11:39 PM, 王珂 <[EMAIL PROTECTED]> 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
Thanks Kent. Your code works, and robocopy process exit when download complete. When I try: p = subprocess.Popen(["robocopy.exe" +" " + "DownloadArgs"],Shell = True,stdout = PIPE) while True: line = p.stdout.readline() if not line: break time.sleep(5) ### new added print ">", then robocopy download will never complete. It seems, when call sleep() here, the subprocess will sleep too. Is that the cause? Thanks again. When subprocess running, how can I print some character on console window on a period of time? (Used to tell user the subprocess is still running)
_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
