Created
April 15, 2012 05:45
-
-
Save wendal/2390303 to your computer and use it in GitHub Desktop.
Lua中拿到os.execute的输出结果
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
-- from http://stackoverflow.com/questions/132397/get-back-the-output-of-os-execute-in-lua | |
function os.capture(cmd, raw) | |
local f = assert(io.popen(cmd, 'r')) | |
local s = assert(f:read('*a')) | |
f:close() | |
if raw then return s end | |
s = string.gsub(s, '^%s+', '') | |
s = string.gsub(s, '%s+$', '') | |
s = string.gsub(s, '[\n\r]+', ' ') | |
return s | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to get the output of os.execute(cmd)?
what is 'raw'?