author | Mikael Berthe <mikael@lilotux.net> |
Tue, 27 Nov 2012 16:26:04 +0100 | |
changeset 66 | d9c00a9fe9d5 |
parent 39 | 237af42156a1 |
permissions | -rw-r--r-- |
66
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
39
diff
changeset
|
1 |
|
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
39
diff
changeset
|
2 |
-- shcmd(command): execute command in a shell and return stdout contents |
3 | 3 |
|
4 |
function shcmd (cmd) |
|
5 |
if not cmd or cmd == "" then return nil, "No command" end |
|
6 |
||
7 |
local fullcmd = cmd.." 2> /dev/null" |
|
8 |
local fh = io.popen(fullcmd) |
|
9 |
result = fh:read("*a") -- read cmd output |
|
10 |
fh:close() |
|
39
237af42156a1
Add checks after shcmd() calls
Mikael Berthe <mikael@lilotux.net>
parents:
3
diff
changeset
|
11 |
if not result then return nil end |
3 | 12 |
-- Trim trailing newlines |
13 |
local r = result:gsub("\n+$", "") |
|
14 |
return r |
|
15 |
end |