[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: io.popen of unknown program succeeds
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sat, 28 Dec 2013 11:04:43 +0200
2013/12/28 Philipp Janda <siffiejoe@gmx.net>:
> But you can find out (in Lua 5.2) by calling the `close` method on the
> returned file pointer:
>
> > print( io.popen( "no_such_program" ):close() )
> sh: 1: no_such_program: not found
> nil exit 127
> > print( io.popen( "false" ):close() )
> nil exit 1
> > print( io.popen( "true" ):close() )
> true exit 0
So one could use this instead of io.popen?
function popen(prog,mode)
local cond,msg,code = io.popen(prog,mode):close()
if code==127 then error("'"..prog.."' not found") end
return io.popen(prog,mode)
end