python - 如何读取通过 Python 中的 subprocess.popen 生成的文件的输出?

标签 python subprocess bitcoin

我已经开始尝试为比特币矿工编写 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/

相关文章:

python - 如何在 Ubuntu 上找到 pyenv 安装的 Python 3 的主目录和 dll 路径?

python - FFMPEG + Python - 在 ffmpeg 端跳过不需要的帧

python - 比特币地址的 Base58Check 编码太长

Angular 4, typescript 将接口(interface)属性分配给变量

c - 使用两个管道的双向进程间通信

magento - 如何安装 Magento 比特币货币扩展?

python - 从 PST -8 0 到其字母名称的时区转换

python - 单击按钮并按回车键时调用相同的函数

Python:从文本文件导入列表并根据多列进行排序/平均

python - xterm python 子进程