modules/admin-mini: add missing ltn12_popen()
This commit is contained in:
parent
564649cb92
commit
876b33a1dd
1 changed files with 30 additions and 0 deletions
|
@ -218,3 +218,33 @@ function _keep_pattern()
|
||||||
end
|
end
|
||||||
return kpattern
|
return kpattern
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ltn12_popen(command)
|
||||||
|
|
||||||
|
local fdi, fdo = nixio.pipe()
|
||||||
|
local pid = nixio.fork()
|
||||||
|
|
||||||
|
if pid > 0 then
|
||||||
|
fdo:close()
|
||||||
|
local close
|
||||||
|
return function()
|
||||||
|
local buffer = fdi:read(2048)
|
||||||
|
local wpid, stat = nixio.waitpid(pid, "nohang")
|
||||||
|
if not close and wpid and stat == "exited" then
|
||||||
|
close = true
|
||||||
|
end
|
||||||
|
|
||||||
|
if buffer and #buffer > 0 then
|
||||||
|
return buffer
|
||||||
|
elseif close then
|
||||||
|
fdi:close()
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif pid == 0 then
|
||||||
|
nixio.dup(fdo, nixio.stdout)
|
||||||
|
fdi:close()
|
||||||
|
fdo:close()
|
||||||
|
nixio.exec("/bin/sh", "-c", command)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue