曲径通幽论坛

标题: 在LUCI中调用系统命令及脚本 [打印本页]

作者: beyes    时间: 2014-12-15 21:33
标题: 在LUCI中调用系统命令及脚本
在 LUCI 中调用系统命令及脚本使用函数 luci.sys.call() ,比如:
luci.sys.call ("echo hello > /tmp/test.txt")

这样就会在 /tmp 下生成含有 hello 字串的 test.txt 文件。

luci.sys.call() 返回值是命令的错误代码,比如:
local rstatus = (luci.sys.call ("echo hello > /tmp/test.txt") == 0)

if rstatus then
        ...

一般 shell 命令执行成功时返回值为 0,那么上面代码中,若正常生成了 /tmp/test.txt 文件,那么 0 == 0 为真,即 rstatus 的值为 true 。





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2