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

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

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -