lua-users home
lua-l archive

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


Hello listers,

I am trying to load a table with lines from a shell output. However, I am not able to understand what is wrong.

#!./usr/bin/env lua

function execute(command)
local lines = {}
local file = io.popen(command)
 while true do
line = file:read('*l')
table.insert(lines, line)
if line == nil then break
end
file:close()
return lines
end

output = execute('ls')
print(output[2])

Each line of the table should contain a line from the output, but in stead of it, I have a looping.

Luciano