开发者

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

开发者 https://www.devze.com 2023-03-15 02:12 出处:网络
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 st

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

精彩评论

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

关注公众号