How can I capture the stdout output of a child process?

前端 未结 2 1372
滥情空心
滥情空心 2020-12-05 20:21

I\'m trying to write a program in Python and I\'m told to run an .exe file. When this .exe file is run it spits out a lot of data and I need a certain line printed out to th

2条回答
  •  死守一世寂寞
    2020-12-05 21:00

    Something like this:

    import subprocess
    process = subprocess.Popen(["yourcommand"], stdout=subprocess.PIPE)
    result = process.communicate()[0]
    

提交回复
热议问题