lua io.read()


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 命令可得:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM