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 :
from flask import Flask
app = Flask(__name__)
cmd = ["ls"," -l"]
p = subprocess.Popen(cmd, stdout = subprocess.PIPE,
out,err = p.communicate()
if __name__ == "__main__" :
It's a simple typo.
cd in the following line should be
p = subprocess.Popen(cd, # <---- stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
There's another typo; remove a space in the second item:
cmd = ["ls", " -l"] ^