mcbot/libs/shcmd.lua
author Mikael Berthe <mikael@lilotux.net>
Sun, 25 Nov 2012 19:29:32 +0100
changeset 65 2cefbe9f3ac6
parent 39 237af42156a1
child 66 d9c00a9fe9d5
permissions -rw-r--r--
shortenurl: cosmetical change


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