gpt4 book ai didi

python - 我如何使用 Tornado 提供(永无止境的)系统调用

转载 作者:太空宇宙 更新时间:2023-11-03 19:32:30 24 4
gpt4 key购买 nike

例如,假设我有以下代码:

def dump():
tcpdump = subprocess.Popen("tcpdump -nli any",
stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
outputfile = tcpdump.stdout

for line in outputfile:
print line,

如何将此类输出提供给浏览器?由于没有停止点,我不知道在哪里 Hook 轮询循环。更重要的是,当打印行工作时(我看到终端上转储的行),浏览器不会得到完全相同的行,见下文:

class TCPDumpHandler(tornado.web.RequestHandler):
def get(self):
self.write("<form method='post' action='/log'><input type='submit'></form>")

@tornado.web.asynchronous
def post(self):
tcpdump = subprocess.Popen("tcpdump -nli any",
stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
outputfile = tcpdump.stdout

for line in outputfile:
print line,
self.write(line)

self.finish()

最佳答案

将 tcpdump 的输出重定向到文件并使用:

https://bitbucket.org/silverspell/tornadolog

希望有帮助:)

关于python - 我如何使用 Tornado 提供(永无止境的)系统调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5090828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com