我正在尝试使用vnstat在python中进行实时带宽监视。不幸的是,它没有打印我想要的输出,而且我似乎无法弄清楚原因。这是我的下面的代码。from subprocess import Popen, PIPEimport timedef run(command): process = Popen(command, stdout=PIPE, bufsize=1, shell=True ,universal_newlines=True) while True: line = process.stdout.readline().rstrip() print(line)if __name__ == "__main__": run("sudo vnstat -l -i wlan1") 当我在终端中运行此代码时,这是我得到的输出:sudo python testingLog.pyMonitoring wlan1... (press CTRL-C to stop)在终端中运行“ vnstat -l -i wlan1”时,它没有显示所需的输出。所需输出:Monitoring wlan1... (press CTRL-C to stop)rx: 0 kbit/s 0 p/s tx: 0 kbit/s 0 p/s当我运行vnstat -l -i wlan1时会发生什么,它将对其进行更新并实时运行,因此我怀疑我的打印错误,因为它无法打印所需的输出,但我似乎无法弄清楚原因。
添加回答
举报
0/150
提交
取消
