zoukankan      html  css  js  c++  java
  • 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 命令可得:

  • 相关阅读:
    软件工程基础
    第一个微信小项目
    数据库实践
    爬虫
    模拟体育竞技
    自己的第一个网页
    科学计算和可视化
    结队项目
    自动生成小学四则运算
    自动生成小学四则运算
  • 原文地址:https://www.cnblogs.com/rohens-hbg/p/8066789.html
Copyright © 2011-2022 走看看