从flask启动时,subprocess和os.system不起作用

问题描述 投票:-1回答:1

我需要使用python代码运行一个命令,我试图同时使用os.system和subprocess,但是由于某些原因它们都不起作用。这是我的代码:

@app.route('/run-script')
def run_script():
   subprocess.call('python3.6 GoReport.py --id 31-33 --format word', cwd="working_dir", shell=True)
   return flask.render_template('results.html', **locals())

直接从终端运行此命令可以正常工作。尝试使用命令行从python解释器重现这一点也可以作为一个魅力。但是当我使用Flask时它不起作用。这是什么原因?

python flask terminal subprocess os.system
1个回答
0
投票

所以我设法编辑我的代码并导入模块,而不是使用subprocess和os.system。谢谢@tripleee的解释!

© www.soinside.com 2019 - 2024. All rights reserved.