lua-users home
lua-l archive

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


On Sat, Dec 28, 2013 at 11:11 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> I have to agree with Luiz, use luaposix.  You can do all that lovely
> fork and exec stuff, and signal away like it was 1976

Although you can get pretty far with this:

function popen(cmd)
   local f = io.popen('('..cmd .. ' || echo "++failed $?++") 2>&1','r')
   local res = f:read '*a'
   f:close()
   return res
end

> s = popen 'boo'
> = s
sh: 1: boo: not found
++failed 127++

> s = popen 'which gcc'
> = s
/usr/bin/gcc

A variation I like is to strip off the trailing '\n' from the output.

steve d.