0

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

Ondiek Elijah
  • 547
  • 8
  • 15

1 Answers1

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)