io.read(...)
从文件中读取内容,还有另外一种写法就是 file:read()
后面可以跟的读取方式有:
(1) "n" 读取一个数字,这是唯一一个返回数字而不是字符串的格式
(2) "a" 从当前位置开始剩余的所有字符串,如果在文件末尾,则返回空串""
(3) "l" 读取下一行内容,如果在文件末尾,则会返回nil
eg:
function action_bandwidth(iface)
luci.http.prepare_content("application/json")local bwc = io.popen("luci-bwc -i %q 2>/dev/null" % iface)
if bwc then luci.http.write("[")while true do
local ln = bwc:read("*l") if not ln then break end luci.http.write(ln) endluci.http.write("]")
bwc:close() endend在串口掉好用 luci-bwc 命令可得: