lua中如何使用os.execute实现io.popen的find功能

function QMPlugin.setarea1()
    local files = find_file("/User/Containers/Data/Application/*/Documents/clientconfig")
    if #files > 0 then
        local clientconfig = files[1]
        if #files > 1 then
            LuaAuxLib.TracePrint("发现"..#files.."个clientconfig文件目录!(自动清理)", 3)
            local latest_file = nil
            for k, f in pairs(files) do
                if latest_file == nil then
                    latest_file = f
                else
                    local r = io.popen("find "..latest_file.." -newer "..f)
                    local old_file = f
                    if not r then 
                        old_file = latest_file
                        latest_file = f
                    end

                    -- 删除旧文件
                    local dir = string.sub(old_file, 1, -23)
                    remove_file(dir)
                end
            end
            clientconfig = latest_file
        end

        local content = read_file(clientconfig)
        return content--按键中decode后返回
    else
        LuaAuxLib.TracePrint("无法找到clientconfig文件目录!")
    end
end
function QMPlugin.setarea2(area_set,config)
        config.areaSetId = area_set.areaSetId
        config.areaSet = area_set.areaSet
        config.quick_help_info = nil
        config.local_all_login_record = nil
        return config--按键中encode
end
function QMPlugin.setarea3(config)
        local files = find_file("/User/Containers/Data/Application/*/Documents/clientconfig")
    if #files > 0 then
        local clientconfig = files[1]
        if #files > 1 then
            LuaAuxLib.TracePrint("发现"..#files.."个clientconfig文件目录!(自动清理)", 3)
            local latest_file = nil
            for k, f in pairs(files) do
                if latest_file == nil then
                    latest_file = f
                else
                    local r = io.popen("find "..latest_file.." -newer "..f)
                    local old_file = f
                    if not r then 
                        old_file = latest_file
                        latest_file = f
                    end

                    -- 删除旧文件
                    local dir = string.sub(old_file, 1, -23)
                    remove_file(dir)
                end
            end
            clientconfig = latest_file
        end

        local content = read_file(clientconfig)
        --return content--按键中decode后返回
    else
        LuaAuxLib.TracePrint("无法找到clientconfig文件目录!")
    end


        write_file(clientconfig,config)
        return true
end

function find_file(path)
    local a = io.popen("find "..path.." -prune")
    local f = {};
    for l in a:lines() do
        table.insert(f,l)
    end
    return f
end
function remove_file(path)
    return os.execute("rm -rf " .. path)
end
function read_file(file_name)
    local f = io.open(file_name, "r")
    if f ~= nil then
        local data = f:read("*a")
        f:close()
        return data
    end
end
function write_file(file_name, data)
    local f = io.open(file_name, "w")
    if f ~= nil then
        f:write(data)
        f:close()
    end
end


一共3处popen,2处重复
1.io.popen("find "..path.." -prune")
2.io.popen("find "..latest_file.." -newer "..f)
怎么使用os.execute才能实现相同操作

os.execute 和 os.popen 都是一个执行器,以来的是内部实现的命令。os.execute 执行后返回错误码,而os.popen执行后返回file对象。
如果要用os.execute 实现,你可以用 c 语言写一个,然后让 os.execute 执行就可以了。但我猜你应该都用脚本实现。os.execute 不会比os.popen
更便捷。

有没有办法将popen执行后出错的结果也获取到并存在一个变量里面?

比如我执行io.popen('dddd')会出错,但我就是想要获得终端的出错信息,并存起来