lazuscripts-utility/shell.moon
Paul Liverman III c615ea4b1f re-initialized
tl;dr: rewriting history of this repo because I have accidentally
included the history of OTHER repos in it due to either a bug with
git subtree or a misunderstanding of how it functions on my part
2018-03-04 11:41:07 -08:00

19 lines
399 B
Plaintext

execute = (cmd, capture_exit_code=true) ->
local handle
if capture_exit_code
handle = io.popen "#{cmd}\necho $?"
else
handle = io.popen cmd
result = handle\read "*a"
handle\close!
exit_start, exit_end = result\find "(%d*)[%c]$"
exit_code = tonumber result\sub(exit_start, exit_end)\sub 1, -2
output = result\sub 1, exit_start - 1
return exit_code, output
{
:execute
}