From: Steven Barth Date: Thu, 14 Aug 2008 21:55:43 +0000 (+0000) Subject: libs/core: Add luci.execi as memory efficient replacement for now deprecated luci... X-Git-Tag: 0.8.0~425 X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=2b0e8c6d7fc72c5c4d090dd3311c341f280e2237;p=project%2Fluci.git libs/core: Add luci.execi as memory efficient replacement for now deprecated luci.execl --- diff --git a/libs/core/luasrc/util.lua b/libs/core/luasrc/util.lua index 638bb056a7..51d66e08e5 100644 --- a/libs/core/luasrc/util.lua +++ b/libs/core/luasrc/util.lua @@ -594,9 +594,24 @@ function exec(command) return data end ---- Execute given commandline and gather stdout. +--- Return a line-buffered iterator over the output of given command. -- @param command String containing the command to execute --- @return Table containing the command's stdout splitted up in lines +-- @return Iterator +function execi(command) + local pp = io.popen(command) + + return pp and function() + local line = pp:read() + + if not line then + pp:close() + end + + return line + end +end + +-- Deprecated function execl(command) local pp = io.popen(command) local line = ""