Currently, I am in the process of building an application that is capable of executing shell commands and fetching the results to a web browser. My problem is that the results display fine on the browser but not in real-time. The command I'm having trouble with is the Linux 'top' command. And as we know, this command sends the list of processes executed on the system as well as the CPU, RAM and in real-time. Is it possible to do this with Flask ??? I've seen similar posts before but they didn't help me. And frankly, I'm still new to flask and your help will be very useful to me. thanks in advance
Asked
Active
Viewed 520 times
0
-
That is totally possible, but you need to use Javascript for the "realtime" aspect. – Jürgen Gmach Jul 30 '21 at 20:11
1 Answers
0
Following is the code I've tried. (the command is in the test.sh file)
import flask
from shelljob import proc
app = flask.Flask(__name__)
@app.route( '/stream' )
def stream():
g = proc.Group()
p = g.run( [ "./test.sh" ] )
def read_process():
while g.is_pending():
lines = g.readlines()
for proc, line in lines:
yield line
retour = flask.Response( read_process(), mimetype= 'text/json' )
return retour
@app.route('/exec')
def streaming():
return flask.render_template('index.html')
if __name__ == "__main__":
app.run(debug=True)

Stan1234
- 11