real time subprocess.Popen via stdout and PIPE

前端 未结 8 1442

I am trying to grab stdout from a subprocess.Popen call and although I am achieving this easily by doing:

cmd = subprocess.Popen(\'         


        
相关标签:
8条回答
  • 2020-11-30 05:47
    cmd = subprocess.Popen(["ls", "-l"], stdout=subprocess.PIPE)
    for line in cmd.stdout:
        print line.rstrip("\n")
    
    0 讨论(0)
  • 2020-11-30 05:50

    The call to readlines is waiting for the process to exit. Replace this with a loop around cmd.stdout.readline() (note singular) and all should be well.

    0 讨论(0)
提交回复
热议问题