title: Running a shell command from a flask app
body: <p>I'm trying to run a shell command from a flask app and trying to grab the output. The app I'm trying with is following:</p>
  
  <pre><code>from flask import Flask
  import subprocess
  
  app = Flask(__name__)
  
  @app.route("/")
  
  def hello():
      cmd = ["ls"," -l"]
      p = subprocess.Popen(cmd, stdout = subprocess.PIPE,
                              stderr=subprocess.PIPE,
                              stdin=subprocess.PIPE)
      out,err = p.communicate()
      return out
  if __name__ == "__main__" :
      app.run()
  </code></pre>
  
  <p>The shell command is ok. I checked it outside, but from the browser I'm getting "internal sever error".</p>
  
  <p><em>EDIT: As the first answer pointed out it had a typo...But now its running ok but I'm not getting any output in my browser...</em></p>