real time updating of subprocess.Popen()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DecDon82
    New Member
    • Feb 2012
    • 1

    real time updating of subprocess.Popen()

    Hii I am new to python and I would like to know how to update the output using the subprocess.Pope n() 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...
    Ex:
    File_Name.py
    Code:
    i=0
    while i <= 1000 :
      time.sleep(1)
      print "waiting for 1 second for the %s time"%i
      i=i+1
    cmd ='python File_Name.py" '
    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.Pope n(cmd,bufsize=0 ,stdout=subproc ess.PIPE, shell = True )
    Code:
    while True :
      line = OP.stdout.readline()
      if not line: break
      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,

    DecDon
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    There are wrappers around subprocess that may make your life easier. I haven't used them so can not say.

    See "Foreground Processes"
    GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.


    Envoy
    Python Subprocesses for Humans™. Contribute to not-kennethreitz/envoy development by creating an account on GitHub.

    Comment

    Working...