T
T
Tremo2016-11-24 13:45:53
Flask
Tremo, 2016-11-24 13:45:53

How to run a separate python script and display output on html page in Flask?

Good day.
The situation is the following. I'm making a web application on a flask. I want another script (for example, test.py ) to be launched by pressing the button and output the output not to the terminal, but to the html page.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fadi Haj, 2016-11-24
@fdhaj

Look towards subprocess .
Example:

import subprocess

# ...

@app.route('/run/<script>')
def run(script):
    reply = subprocess.run(["python", script], stdout=subprocess.PIPE)

    return reply.stdout

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question