1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <assert.h>
- #include "private.h"
- bool_t clish_script_callback(const clish_shell_t * this,
- const clish_command_t * cmd, const char *script)
- {
- FILE *wpipe;
- const char * shebang = NULL;
- assert(this);
- assert(cmd);
- if (!script)
- return BOOL_TRUE;
- shebang = clish_command__get_shebang(cmd);
- #ifdef DEBUG
- if (shebang)
- fprintf(stderr, "SHEBANG: #!%s\n", shebang);
- fprintf(stderr, "SYSTEM: %s\n", script);
- #endif
- if (!shebang)
- return (0 == system(script)) ? BOOL_TRUE : BOOL_FALSE;
-
- wpipe = popen(shebang, "w");
- if (!wpipe)
- return BOOL_FALSE;
- fwrite(script, strlen(script) + 1, 1, wpipe);
- return (0 == pclose(wpipe)) ? BOOL_TRUE : BOOL_FALSE;
- }
- bool_t clish_dryrun_callback(const clish_shell_t * this,
- const clish_command_t * cmd, const char *script)
- {
- #ifdef DEBUG
- fprintf(stderr, "DRY-RUN: %s\n", script);
- #endif
- return BOOL_TRUE;
- }
|