[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Right way to emty stdin?
- From: Gilles Ganault <gilles.ganault@...>
- Date: Wed, 23 Feb 2011 18:30:19 +0100
On Wed, 23 Feb 2011 08:34:51 -0500, David Favro <lua@meta-dynamic.com>
wrote:
>io.read() will return an empty string when it encounters the blank line
>which indicates the end of the variable-list, rather than returning nil,
>which occurs when EOF is reached on input (i.e. the pipe from asterisk (AGI)
>or socket (FastAGI) is closed).
Thanks for the explanation. I found that I must not only use the "line
== break" line, but also the "io.write()" right after it, or the loop
won't stop and the script will remain in RAM:
=======
while true do
local line = io.read()
if line == "" then break end
-- Without line below, script never ends
io.write("NOOP ",line,"\n")
end
=======
The documentation only says the script is expected to read all the
data sent to it through stdin, but it doesn't mention having to reply.
>You can implement almost any AGI script _without_ using non-blocking or
>asynchronous I/O, which I've always found require some C functions rather
>than lua's standard I/O library.
I'm fine with using synchronous I/O (I guess Lua's "io" object _is_
synchronous), since the tasks won't take much time anyway.
Thank you.