Groups
Groups
Sign in
Groups
Groups
openresty
Conversations
Labels
About
Send feedback
Help
io.popen 有些命令找不到, 怎么解决path?
70 views
lua
luajit
openresty
Skip to first unread message
dym5...@gmail.com
unread,
Jan 20, 2017, 2:11:59 AM
1/20/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to openresty
代码:
local cmd = ngx.var.arg_cmd or ""
local c , err = io.popen(cmd)
local context = c:read("*all")
c:close()
但是我发现执行不了很多命令,比如ifconfig等 ,结果是path 不对。
Hadals Yang
unread,
Jan 20, 2017, 9:40:23 PM
1/20/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to openresty
建议使用,有个resty shell库,github搜索
在 2017年1月20日星期五 UTC+8下午3:11:59,
dym5...@gmail.com
写道:
Zexuan Luo
unread,
Jan 21, 2017, 8:51:01 PM
1/21/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to openresty
试下FFI:
local ffi = require "ffi"
ffi.cdef[[int putenv(char *string);]]
local function putenv(str)
ffi.C.putenv(ffi.cast("char *", str))
end
putenv('PATH='..os.getenv('PATH')..':/tmp')
io.popen('xxx')
在 2017年1月20日星期五 UTC+8下午3:11:59,
dym5...@gmail.com
写道:
代码:
Zexuan Luo
unread,
Jan 22, 2017, 1:34:17 AM
1/22/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to openresty
我想我误解楼主的意思了……ifconfig 应该在默认的 PATH 路径下,不需要额外解决PATH变量的问题。
Nginx 默认不会继承父进程的环境变量,需要用 env 加白,
比如
env PATH;
参见
http://nginx.org/en/docs/ngx_core_module.html#env
在 2017年1月22日星期日 UTC+8上午9:51:01,Zexuan Luo写道:
dym5...@gmail.com
unread,
Jan 22, 2017, 2:10:25 AM
1/22/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to openresty
利用resty-shell 是一个不错的方法。方便高效
在 2017年1月20日星期五 UTC+8下午3:11:59,
dym5...@gmail.com
写道:
代码:
Reply all
Reply to author
Forward
0 new messages