diff options
| author | ruki <[email protected]> | 2016-04-13 10:13:37 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-04-13 10:13:37 +0800 |
| commit | 097a0d5eb612d898fb8de01d6db7760aed947b4b (patch) | |
| tree | 9c2ad3ffe67da1663953f9b7097721e96156cb18 /xmake/core/base/os.lua | |
| parent | 833bfb207b3f924eaa81feb496cf74e6223d0041 (diff) | |
throw os.run errors
Diffstat (limited to 'xmake/core/base/os.lua')
| -rw-r--r-- | xmake/core/base/os.lua | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 1cdcd0e08..dfec6dc1d 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -24,6 +24,7 @@ local os = os or {} -- load modules +local io = require("base/io") local path = require("base/path") local utils = require("base/utils") local string = require("base/string") @@ -230,6 +231,32 @@ function os.cd(dir) return true end +-- run shell +function os.run(cmd, ...) + + -- make temporary log file + local log = os.tmpname() + + -- run command + if 0 ~= os.execute(cmd .. string.format(" > %s 2>&1", log)) then + + -- make errors + local errors = string.format("%s\nrun: %s failed!", io.readall(log), cmd) + + -- remove the temporary log file + os.rm(log) + + -- failed + return false, errors + end + + -- remove the temporary log file + os.rm(log) + + -- ok + return true +end + -- raise an exception and abort the current script -- -- the parent function will capture it if we uses pcall or xpcall |
