[英]How to get real-time subprocess output?
I'm trying to call the command "tail - f" on the server to be displayed in real time in this html page.我正在尝试在服务器上调用命令“tail - f”以在此 html 页面中实时显示。 In this case no success, only simple output commands, instant cast.
在这种情况下没有成功,只有简单的输出命令,即时施法。 How do I use subprocess in the flask to real-time command output?
如何在烧瓶中使用子进程实时命令输出?
app.py应用程序
from subprocess import Popen,PIPE
from flask import Flask, render_template,request,
app = Flask(__name__)
@app.route( "/", methods=['GET', 'POST'])
def index():
return render_template('index.html')
@app.route('/page', methods=['GET', 'POST'])
def fist():
with Popen(['tail-f','/var/log/syslog'],stdout=PIPE,stderr=PIPE) as a:
out,err = a.communicate()
data0 = out.decode('utf-8')
return render_template('page.html',data0=data0)
if __name__ == "__main__":
app.run(debug=True)
page.html页面.html
<!DOCTYPE html>
<html>
<head>
<style>
.exit_data{
overflow: hidden;
width: auto;
height: auto;
overflow-y: scroll;
background-color: white;
}
</style>
<title>Page TEST</title>
<body>
<div>
<h2>TEST OUTPUT</h2>
</div>
<div class="exit_data">
{{data0}}
</div>
</body>
</head>
</html>
{{end}}
您应该使用 websocket 并继续将输出流的内容推送到浏览器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.