Re: io.popen : how to retrieve the return code.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: io.popen : how to retrieve the return code.
- From: David Manura <dm.lua@...>
- Date: 2012年1月13日 21:35:07 -0500
On Fri, Jan 13, 2012 at 7:37 PM, Laurent FAILLIE <l_faillie@yahoo.com> wrote:
> In LUA, the only way I found to retrieve the output of a command is to use
> io.popen() then io.read() ... but in this case I'm loosing the return code.
In Lua 5.2, the `file:close` method for files returned by io.popen
will return the error code. [1] You can devise workarounds in 5.1
such as calling os.execute to invoke some command that writes the exit
code to a file, perhaps stdout. Or just re-implement io.popen like
5.2 does. There are also some third-party libraries with more
advanced, though less portable, process manipulation capabilities
(e.g. on win32).
[1] http://www.lua.org/manual/5.2/manual.html#pdf-file:close