Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/sys.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClement Farabet <clement.farabet@gmail.com>2012-08-20 19:46:48 +0400
committerClement Farabet <clement.farabet@gmail.com>2012-08-20 19:46:48 +0400
commit2f5d5758abfcdc0d83bb994e8e718aeda248fdba (patch)
treef3719cbffead85695ee06a4876e03c33b2ce53ff
parentfa78bbfdbe876d9eda740fc70f59c434b4b39cdd (diff)
ARG>
-rw-r--r--init.lua15
1 files changed, 12 insertions, 3 deletions
diff --git a/init.lua b/init.lua
index 9718919..9465bf9 100644
--- a/init.lua
+++ b/init.lua
@@ -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