Execute linux command in Python Flask
import subprocess
from flask import Flask
app = Flask(__name__)
def run_command(command):
return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).stdout.read()
@app.route('/<command>')
def command_server(command):
return run_command(command)
# Then run in server:
# export FLASK_APP=server.py
# flask run
# You can run the below command insteed of the above to make public your server
# flask run --host=0.0.0.0