Skip to content

Instantly share code, notes, and snippets.

@erikLundstedt
Forked from dukeofgaming/os.capture
Last active September 30, 2022 12:54
Show Gist options
  • Save erikLundstedt/ceb688bec8181d67fcccc37c4e959b54 to your computer and use it in GitHub Desktop.
Save erikLundstedt/ceb688bec8181d67fcccc37c4e959b54 to your computer and use it in GitHub Desktop.
Capture console output from Lua system call
---
-- Function to retrieve console output
--
local shell={}
function shell.capture(cmd)
local handle = assert(io.popen(cmd, 'r'))
local output = assert(handle:read('*a'))
handle:close()
local raw=output
output = string.gsub(
string.gsub(
string.gsub(output, '^%s+', ''),
'%s+$',
''
),
'[\n\r]+',
' '
)
local o={}
o["out"] = output
o["raw"] = raw
return o
end
return shell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment