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()
精彩评论