命令执行相关示例代码 (os.execute)
重启设备
os.execute('reboot')
注销设备
os.execute('killall -9 SpringBoard backboardd')
重建图标缓存
os.execute('su mobile -c uicache')
创建脚本日志符号链接到脚本目录
os.execute('ln -s /private/var/mobile/Media/1ferver/log/sys.log /private/var/mobile/Media/1ferver/lua/scripts/脚本日志.txt')
常用操作封装
local function sh_escape(path)
path = string.gsub(path, "([ \\()<>'\"`#&*;?~$])", "\\%1")
return path
end
function fdelete(path)
assert(type(path)=="string" and path~="", 'fremove 参数异常')
os.execute('rm -rf '..sh_escape(path))
end
function frename(from, to)
assert(type(from)=="string" and from~="", 'frename 参数 1 异常')
assert(type(to)=="string" and to~="", 'frename 参数 2 异常')
os.execute('mv -f '..sh_escape(from).." "..sh_escape(to))
end
function fcopy(from, to)
assert(type(from)=="string" and from~="", 'fcopy 参数 1 异常')
assert(type(to)=="string" and to~="", 'fcopy 参数 2 异常')
os.execute('cp -rf '..sh_escape(from).." "..sh_escape(to))
end
function mkdir(path)
assert(type(path)=="string" and path~="", 'mkdir 参数异常')
os.execute('mkdir -p '..sh_escape(path))
end
function openurl(url)
assert(type(url)=="string" and url~="", 'openurl 参数异常')
os.execute('uiopen '..sh_escape(url))
end
fdelete("/var/mobile/1.png")
frename("/var/mobile/2.png", "/var/mobile/1.png")
frename("/var/mobile/1.png", "/var/mobile/Media/1ferver/res/3.png")
fcopy("/var/mobile/1.png", "/var/mobile/Media/1ferver/res/4.png")
mkdir("/var/mobile/1/2/3/4")
openurl("http://www.google.com")