我需要写一些代码来识别(和捕获)何时我的服务器上有传入/传出的smb传输。我认为最好的方法是将popen与'iftop‘一起使用。
我想我可以使用popen来捕获数据,但问题是iftop并不是简单地输出数据--它是一个交互环境,会持续运行直到用户退出。那么,如何才能将这些程序中的值解析成python呢?
或者--一个比popen(iftop)更好的选择?
示例:
foo.Popen("iftop" + someArguments)
//this is not stdout, so I can't pull string values (etc) from it :(
//how does?发布于 2016-09-02 15:24:33
import subprocess, time
s = subprocess.Popen("iftop -s -t 1",shell=True,stdout=subprocess.PIPE)
while not s.poll() == 0:
time.sleep(1)
print(s.stdout.read())https://stackoverflow.com/questions/21654223
复制相似问题