开发者

How do I read the output for a file spawned through subprocess.popen in Python?

I've started playing around with writing a GUI for a bitcoin miner and right now I just have a window with a "Start" and "Stop" button and I've got tho开发者_如何学JAVAse working so you click start and it uses self.p = subprocess.Popen(args) to open the process and self.p.terminate() to end the process. My next step is to read the speed of the miner from it's output. How do I read the output from the process?


Use Popen.communicate to read the output. For example.

import subprocess

p = subprocess.Popen('ls', stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# returns a tuple containing the the stdout and stderr of the program
res, err = p.communicate() 


you call:

out, err = p.communicate()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜