lua-users home
lua-l archive

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


Thanks, that worked! I haven't dealt with stdin, etc. for many years and just didn't even think of it. Now I see in the book, that it mentions "standard input".

Michael

----- Original Message ----- From: "Ico" <lua@zevv.nl>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Wednesday, August 12, 2009 11:53 AM
Subject: Re: Why can't I read a file using io.read?




* On 2009-08-12 Michael Newberry <mnewberry@mirametrics.com> wrote  :

I've been using lua for almost 15 years and I've never had to use the io package before now. I can't get it to work. The fragment below returns a nil string.

I know the file name (sName, which is a full path) is good and that the file has multiple lines of text inside it. I printed the handle (nFile) returned by io.open and it is non zero.


nFile, sMsg = io.open( sName, "r" )
if not nFile then Exit(sMsg) end

for i = 1, 10000000 do
  local sLine = io.read("*line")

You're reading from stdin, instead of from your newly opened filehandle.
Try:

local sLine = nFile:read("*l")

--
:wq
^X^Cy^K^X^C^C^C^C