lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sat, Jun 6, 2009 at 10:07 AM, Patrick Donnelly<batrick@batbytes.com> wrote:
> I believe you meant: "|| echo $?"

This is a fuller elaboration of the hack; you get the status code any
way (because you will need to strip it out with some pattern)

I checked out luaex, but ex.popen gives you a process-object and a
file handle. No way to tell from that, it appears.

steve d.

function command(cmd)
    local f = io.popen(cmd..'; echo "-retcode:$?"' ,'r')
    local l = f:read '*a'
    f:close()
    local i1,i2,ret = l:find('%-retcode:(%d+)\n$')
    l = l:sub(1,i1-1)
    return l,ret
end

print(command 'which lua')