flask-socketio中使用cmd,subprocess.Popen实时输出

flask-socketio中使用cmd

#python 3.5
try:
    cmd = 'ping www.baidu.com'
    p = subprocess.Popen(cmd, stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
    while True:
        for line in iter(p.stdout.readline, b''):
            a = line.decode('gbk')
            gevent.sleep(0)  # 关键
            emit('server_default_response', {'data': a})
        if p.poll() is not None:
            break
except Exception as e:
    return False
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jingza/article/details/79958044
个人分类: python
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭