[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Getting a table from commandline output
- From: Luciano de Souza <luchyanus@...>
- Date: Sun, 06 Nov 2011 12:18:37 -0200
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