简体   繁体   English

双参数 URL flask 执行 bash 脚本

[英]double parameter URL flask execute bash script

How to write the flask approute to execute bash script if I have double parameters in the URL call?如果我在 URL 调用中有双重参数,如何编写 flask approute 来执行 bash 脚本? Here is my URL I am calling from browser http://0.0.0.0:5000/sample/fwd I was trying to write my flask approute like this.这是我从浏览器http://0.0.0.0:5000/sample/fwd调用的 URL

app = Flask(__name__)

@app.route('/<port>')
def get_shell_script_output_using_check_output(port):
    stdout = check_output(['./route.sh','-a',"{}".format(port)]).decode('utf-8')
    return stdout

@app.route('/<port>/<fwd>')
def get_shell_script_output_using_check_output(port,fwd):
    stdout = check_output(['./shadowSR.sh',"{}".format(port),"{}".format(fwd)]).decode('utf-8')
    return stdout

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

But this is not working.但这不起作用。 Can any one suggest me how to mention the approute?谁能建议我如何提及approute?

you can try this你可以试试这个

@app.route('/run/<port>/<fwd>')
def run(port, fwd):
    stdout = check_output(['./shadowSR.sh',"{}".format(port),"{}".format(fwd)]).decode('utf-8')
    return stdout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM