Created
June 9, 2014 04:08
-
-
Save dukeofgaming/453cf950abd99c3dc8fc to your computer and use it in GitHub Desktop.
Capture console output from Lua system call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
-- Function to retrieve console output | |
-- | |
function os.capture(cmd, raw) | |
local handle = assert(io.popen(cmd, 'r')) | |
local output = assert(handle:read('*a')) | |
handle:close() | |
if raw then | |
return output | |
end | |
output = string.gsub( | |
string.gsub( | |
string.gsub(output, '^%s+', ''), | |
'%s+$', | |
'' | |
), | |
'[\n\r]+', | |
' ' | |
) | |
return output | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment