By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,761 Members | 1,018 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,761 IT Pros & Developers. It's quick & easy.

real time updating of subprocess.Popen()

P: 1
Hii I am new to python and I would like to know how to update the output using the subprocess.Popen() process. My problem is similar to real time updating of popen, bufsize=0 problems ... but the only variation is that, I would like to get the print statements from the python file like...
Expand|Select|Wrap|Line Numbers
  1. i=0
  2. while i <= 1000 :
  3.   time.sleep(1)
  4.   print "waiting for 1 second for the %s time"%i
  5.   i=i+1
cmd ='python" '
I have a python script which has this piece of code and would like to print it when i execute this file using:
ret = subprocess.Popen(cmd,bufsize=0,stdout=subprocess.P IPE, shell = True )
Expand|Select|Wrap|Line Numbers
  1. while True :
  2.   line = OP.stdout.readline()
  3.   if not line: break
  4.   print line
print "End of print statements..."

I am unable to get the output of the script while running the script. (The whole data is being shown at once at the end of theexecution). Is there anyway to handle this situation..I tried the solution that has been referred earlier, but it works only for batch file not for script... :-(

Thanks in advance,

Feb 8 '12 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 626
There are wrappers around subprocess that may make your life easier. I haven't used them so can not say.

See "Foreground Processes"

Feb 10 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.