python - Getting output of a process at runtime -


i using python script run process using subprocess.popen , simultaneously store output in text file print on console. code:

result = subprocess.popen(cmd, shell=true, stdout=subprocess.pipe) line in result.stdout.readlines(): #read , store result in log file     openfile.write("%s\n" %line)     print("%s" %line) 

above code works fine, first completes process , stores output in result variable. after for loop stores output print it.

but want output @ runtime (as process can take hours complete, don't output these hours).

so there other function gives me output dynamically (at runtime), means process gives first line, should printed.

the problem here .readlines() gets entire output before returning, constructs full list. iterate directly:

for line in result.stdout:     print line 

Comments

Popular posts from this blog

How can I fetch data from a web server in an android application? -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -

jquery - How can I dynamically add a browser tab? -