lua运行带参数的shell命令无效

我试图从lua脚本中执行一个命令。该命令是简单地运行一个名为"sha_compare.py"的python脚本,其中接收3个参数,其中两个是lua脚本的变量 - dady_data和sha:

local method = ngx.var.request_method
local headers = ngx.req.get_headers()

if method == "POST" then
   ngx.req.read_body()
   local body_data = ngx.req.get_body_data()
   local sha = headers['X-Hub-Signature-256']
   ngx.print(os.execute("python3 sha_compare.py"..sha..body_data))
else

该脚本失败是因为我调用参数的方式。如果我从cmd中运行实际命令将是像这样的:

python3 python3 sha_compare.py sha256=ffs8df aaaaa

请告诉我我应该如何改变我的代码以正确调用具有3个变量的python脚本。

如果不可能或难以实现,请让我知道如何调用将接收这3个参数的.sh脚本。

点赞
用户7552
用户7552

你没有在参数之间提供空格:你试图执行

python3 sha_compare.pysha256=ffs8dfaaaaa

改为:

os.execute("python3 sha_compare.py "..sha.." "..body_data)

通常更容易的方法是将命令构建为一个表格,然后连接它以执行:

local cmd = { 'python3', 'sha_compare.py', sha, body_data }
os.execute(table.concat(cmd, " "))
2021-02-28 14:12:23