mcbot/libs/shcmd.lua
author Mikael Berthe <mikael@lilotux.net>
Wed, 21 Oct 2015 19:10:04 +0200
changeset 73 2ca07b5226c1
parent 66 d9c00a9fe9d5
permissions -rw-r--r--
Update wtfdb


-- shcmd(command): execute command in a shell and return stdout contents

function shcmd (cmd)
    if not cmd or cmd == "" then return nil, "No command" end

    local fullcmd = cmd.." 2> /dev/null"
    local fh = io.popen(fullcmd)
    result = fh:read("*a")  -- read cmd output
    fh:close()
    if not result then return nil end
    -- Trim trailing newlines
    local r = result:gsub("\n+$", "")
    return r
end