我已经开始尝试为比特币矿工编写 GUI,现在我只有一个带有“开始”和“停止”按钮的窗口,我已经让这些按钮工作了,所以你单击开始,它使用 self .p = subprocess.Popen(args) 打开进程, self.p.terminate() 结束进程。我的下一步是从矿工的输出中读取其速度。如何读取进程的输出?
最佳答案
使用 Popen.communicate 读取输出。例如。
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()
关于python - 如何读取通过 Python 中的 subprocess.popen 生成的文件的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6473753/