1

I'm implementing a Flask application and I need my app to run shell scripts, is the a way to do that?

I know that we can run shell commands this way :

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()

But when it comes to a whole script how can I do that?

  • Did you read http://stackoverflow.com/questions/3777301/how-to-call-a-shell-script-from-python-code? – Forge Mar 02 '16 at 08:59

1 Answers1

0

you may need to add "#!/usr/bin/env python" on the top of your python scrip, then you can simply run your scrip by "python "

sachin
  • 379
  • 3
  • 16