Last active
September 4, 2017 17:31
-
-
Save JJRcop/42805610ff748428cd48ee7ae03596e9 to your computer and use it in GitHub Desktop.
shelleo command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Runs the command in the system's shell, returns a list of (error code, stdout, stderr) | |
#define SHELLEO_ERR "data/shelleo.err" | |
#define SHELLEO_OUT "data/shelleo.out" | |
/proc/shelleo(command) | |
var/stdout = "" | |
var/stderr = "" | |
var/errorcode = 1 | |
var/static/list/interpreters = list("[MS_WINDOWS]" = "cmd /c", "[UNIX]" = "sh -c") | |
var/interpreter = interpreters["[world.system_type]"] | |
if(interpreter) | |
errorcode = shell("[interpreter] [command] > [SHELLEO_OUT] 2> [SHELLEO_ERR]") | |
if(fexists(SHELLEO_OUT)) | |
stdout = file2text(SHELLEO_OUT) | |
fdel(SHELLEO_OUT) | |
if(fexists(SHELLEO_ERR) | |
stderr = file2text(SHELLEO_ERR) | |
fdel(SHELLEO_ERR) | |
else | |
CRASH("Operating System: [world.system_type] not supported") // If you encounter this error, you are encouraged to update this proc with support for the new operating system | |
. = list(errorcode, stdout, stderr) | |
#undef SHELLEO_ERR | |
#undef SHELLEO_OUT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment