libs/core: Add luci.execi as memory efficient replacement for now deprecated luci...
authorSteven Barth <steven@midlink.org>
Thu, 14 Aug 2008 21:55:43 +0000 (21:55 +0000)
committerSteven Barth <steven@midlink.org>
Thu, 14 Aug 2008 21:55:43 +0000 (21:55 +0000)
libs/core/luasrc/util.lua

index 638bb056a74d9ded789aa68fc1d4521428307877..51d66e08e5a34b1a6e3423742ae636c637f79a0d 100644 (file)
@@ -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 = ""