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

1
  • That is totally possible, but you need to use Javascript for the "realtime" aspect. Commented Jul 30, 2021 at 20:11

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.