From 2b0e8c6d7fc72c5c4d090dd3311c341f280e2237 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Thu, 14 Aug 2008 21:55:43 +0000 Subject: [PATCH] libs/core: Add luci.execi as memory efficient replacement for now deprecated luci.execl --- libs/core/luasrc/util.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/libs/core/luasrc/util.lua b/libs/core/luasrc/util.lua index 638bb056a..51d66e08e 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 = "" -- 2.25.1