diff options
author | Clement Farabet <clement.farabet@gmail.com> | 2012-08-20 19:46:48 +0400 |
---|---|---|
committer | Clement Farabet <clement.farabet@gmail.com> | 2012-08-20 19:46:48 +0400 |
commit | 2f5d5758abfcdc0d83bb994e8e718aeda248fdba (patch) | |
tree | f3719cbffead85695ee06a4876e03c33b2ce53ff | |
parent | fa78bbfdbe876d9eda740fc70f59c434b4b39cdd (diff) |
ARG>
-rw-r--r-- | init.lua | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -69,11 +69,20 @@ toc = function(verbose) -------------------------------------------------------------------------------- -- execute an OS command, but retrieves the result in a string +-- side effect: file in /tmp -------------------------------------------------------------------------------- execute = function(cmd, readwhat) - local f = io.popen(cmd, 'r') - local s = f:read(readwhat or '*all') - s = s:gsub('^%s*',''):gsub('%s*$','') + local tmpfile = '/tmp/lua.os.execute.out.' .. _G.tostring(clock()) + local cmd = cmd .. ' 1>'.. tmpfile..' 2>' .. tmpfile + os.execute(cmd) + local file = _G.assert(io.open(tmpfile)) + local s = file:read('*all') + file:close() + s:gsub('\n$','') + os.execute('rm ' .. tmpfile) + --local f = io.popen(cmd, 'r') + --local s = f:read(readwhat or '*all') + --s = s:gsub('^%s*',''):gsub('%s*$','') return s end |