Manipulating python stdout/stderr using subprocess -


i trying manipulate/strip output of 7zip command , intimate user progress of process. sample code trying use below:

import subprocess proc = subprocess.popen(['7zip','arg', 'archive'],shell=true, stdin=none, stdout=subprocess.pipe, stderr=subprocess.pipe) while true:   line = proc.stdout.readline()   if line != '':     #do striping , update pyqt label     print "test:", line.rstrip()     sys.stdout.flush()   else:     break 

however, real problem print statement print stdout after completion of process. there way capture stdout line line manipulate , print again?

update updated script include sys.stdout.flush()

yes, popen family of calls.

you can see documentation here

(child_stdin,  child_stdout,  child_stderr) = os.popen3("cmd", mode, bufsize) ==> p = popen("cmd", shell=true, bufsize=bufsize,           stdin=pipe, stdout=pipe, stderr=pipe, close_fds=true) (child_stdin,  child_stdout,  child_stderr) = (p.stdin, p.stdout, p.stderr) 

they give filedescriptors streams , can use them read output of called program.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -