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)
end
luci.http.write("]")
bwc:close()
end
end
在串口掉好用 luci-bwc 命令可得: