Answers for "Execute linux command in Python Flask"

0

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
Posted by: Guest on September-15-2021

Code answers related to "Execute linux command in Python Flask"

Python Answers by Framework

Browse Popular Code Answers by Language