I'm trying to run a subprocess from a Flask route, but I get a 500 error. It works when I run it directly from the shell. Why isn't it working?
import subprocess
from flask import Flask
app = Flask(__name__)
@app.route('/status/<vmid>')
def status(vmid):
    cmd = "/usr/bin/virsh list --all | grep kvm%s | awk {'print $3'}" % vmid
    p = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
    out,err = p.communicate()
    return out
if __name__ == '__main__':
    app.run(host='0.0.0.0')
It raises a 500 error when run through Flask:
root@nc2-kvm:~# python status.py
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
(500 error)
It works when run directly in the shell:
root@nc2-kvm:~# virsh list --all | grep kvm180 | awk {'print $3'}
running
 
     
    