A non-blocking read on a subprocess.PIPE in Python

后端 未结 29 2674
醉酒成梦
醉酒成梦 2020-11-21 04:49

I\'m using the subprocess module to start a subprocess and connect to its output stream (standard output). I want to be able to execute non-blocking reads on its standard ou

29条回答
  •  孤独总比滥情好
    2020-11-21 05:08

    Try wexpect, which is the windows alternative of pexpect.

    import wexpect
    
    p = wexpect.spawn('myprogram.exe')
    p.stdout.readline('.')               // regex pattern of any character
    output_str = p.after()
    

提交回复
热议问题