lua-users home
lua-l archive

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

Hi David,

Thanks for your reply.
Unfortunately, I have to run my scripts on several Gentoo machine and Gentoo's ebuild is still stick on 5.1.

Until 5.2 is packages, I'll workaround by using os.execute and a temporary file ...

Best regards,


From: David Manura <>
To: Laurent FAILLIE <>; Lua mailing list <>
Sent: Saturday, January 14, 2012 3:35 AM
Subject: Re: io.popen : how to retrieve the return code.

On Fri, Jan 13, 2012 at 7:37 PM, Laurent FAILLIE <> wrote:
> In LUA, the only way I found to retrieve the output of a command is to use
> io.popen() then ... 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).