mirror of
https://github.com/lazuscripts/utility.git
synced 2024-11-16 03:14:21 +00:00
c615ea4b1f
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
19 lines
399 B
Plaintext
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
|
|
}
|