[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: io.popen of unknown program succeeds
- From: steve donovan <steve.j.donovan@...>
- Date: Sat, 28 Dec 2013 11:23:30 +0200
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.