title: Python Flask - how to run subprocess (pass a command)?
body: <p>I have a running Flask app but want to pass any command via URL and make flask execute it on a host server and return results.</p>
  
  <p>e.g. when running <code>curl localhost:5000/run/"ls -l"</code> (command is <code>ls -l</code>) -> expecting result:</p>
  
  <pre><code>.
  ..
  file1
  file2
  etc..
  </code></pre>
  
  <p>So far I have:</p>
  
  <pre><code>import os
  
  from flask import Flask
  app = Flask(__name__)
  
  @app.route('/')
  def hello():
      return "Hello World!"
  
  @app.route('/run/&lt;command&gt;')
  def run(command):
     return 'Run this %s!' % command
  
  
  if __name__ == "__main__":  
      app.run(debug = True)
  </code></pre>
  
  <p>Thanks.</p>