Lua的io.popen
对于捕获命令的stdout很有用,但它依赖于/bin/sh
进行分词,全局扩展等。
所以我可以做到以下内容并且效果很好
-- this unfortunately uses /bin/sh
local command = "ls -1";
local ph = io.popen(command, "r")
while true do
local line = ph:read()
if line == nil then
break
end
io.write("I read a line! " .. line .. "\n")
end
io.write("Done with line reading!\n")
是否有一些功能是spawn*
或fork/exec*
周围的薄包装,我可以通过{"ls", "-1"}
来避免shell?