Skip to content

Commit

Permalink
Bring back old version of system() and use mine as execute()
Browse files Browse the repository at this point in the history
  • Loading branch information
voron00 committed Jan 2, 2016
1 parent fe5bfb6 commit 0e11302
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions gsc.cpp
Expand Up @@ -256,6 +256,7 @@ Scr_Function scriptFunctions[] = {
{"getAscii" , gsc_utils_getAscii , 0},
{"toUpper" , gsc_utils_toupper , 0},
{"system" , gsc_utils_system , 0},
{"execute" , gsc_utils_execute , 0},
{"file_link" , gsc_utils_file_link , 0},
{"file_unlink" , gsc_utils_file_unlink , 0},
{"file_exists" , gsc_utils_file_exists , 0},
Expand Down
15 changes: 13 additions & 2 deletions gsc_utils.cpp
Expand Up @@ -529,6 +529,17 @@ void gsc_utils_toupper() {
stackPushString(result);
}

void gsc_utils_system() { // closer 903, "ls"
char *cmd;
if ( ! stackGetParams("s", &cmd)) {
printf("scriptengine> ERROR: please specify the command as string to gsc_system_command()\n");
stackPushUndefined();
return;
}
setenv("LD_PRELOAD", "", 1); // dont inherit lib of parent
stackPushInt( system(cmd) );
}

// http://stackoverflow.com/questions/1583234/c-system-function-how-to-collect-the-output-of-the-issued-command
// Calling function must free the returned result.
char* exec(const char* command) {
Expand Down Expand Up @@ -567,10 +578,10 @@ char* exec(const char* command) {
return result;
}

void gsc_utils_system() { // Returns complete command output as a string
void gsc_utils_execute() { // Returns complete command output as a string
char *cmd;
if ( ! stackGetParams("s", &cmd)) {
printf("scriptengine> ERROR: please specify the command as string to gsc_system_command()\n");
printf("scriptengine> ERROR: please specify the command as string to gsc_execute_command()\n");
stackPushUndefined();
return;
}
Expand Down
1 change: 1 addition & 0 deletions gsc_utils.hpp
Expand Up @@ -20,6 +20,7 @@ void gsc_utils_disableGlobalPlayerCollision();
void gsc_utils_getAscii();
void gsc_utils_toupper();
void gsc_utils_system();
void gsc_utils_execute();
void gsc_utils_file_link();
void gsc_utils_file_unlink();
void gsc_utils_file_exists();
Expand Down

0 comments on commit 0e11302

Please sign in to comment.