flask - Using Python subprocess doesn't work, but calling directly in the shell does -


i'm trying run subprocess flask route, 500 error. works when run directly shell. why isn't working?

import subprocess 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 500 error when run through flask:

root@nc2-kvm:~# python status.py  * running on http://0.0.0.0:5000/ (press ctrl+c quit) (500 error) 

it works when run directly in shell:

root@nc2-kvm:~# virsh list --all | grep kvm180 | awk {'print $3'} running 

take @

https://docs.python.org/2/library/subprocess.html

for subprocess.call work in form you're using, need set shell argument true. make sure works, try subprocess.call in python repl first.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

android - Pass an Serializable object in AIDL -