因此,我正在专用服务器(Ubuntu 16.04,apache2,mod_wgsi)上运行flask应用程序。 我已经在虚拟环境(python 3.5)中编译了flask_app。 现在,我试图获取执行shell脚本的输出:
from flask import Flask, request
import subprocess
app = Flask(__name__)
@app.route('/')
def index():
test_cmd = "/venv/bin/python --version"
try:
result = subprocess.check_output(test_cmd, stderr=subprocess.STDOUT)
except Exception as e:
result = "Unexpected error: {}".format(e)
return result
但是,我得到了错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 567, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory