diff options
-rw-r--r-- | src/cli_new.c | 70 |
1 files changed, 34 insertions, 36 deletions
diff --git a/src/cli_new.c b/src/cli_new.c index a047f36..41afb5f 100644 --- a/src/cli_new.c +++ b/src/cli_new.c @@ -2534,42 +2534,42 @@ old_system_out(const char *command) return ret; } - - int -system_out(const char *cmd, const char **outbuf) -{ - // fprintf(out_stream,"system out\n"); - if (outbuf == NULL) { - return old_system_out(cmd); - } - - if (cmd == NULL) { - return -1; - } - - int cp[2]; // Child to parent pipe - - if( pipe(cp) < 0) { - return -1; - } - - pid_t pid = fork(); - if (pid == 0) { - //child - close(1); // Close current stdout./ - dup2( cp[1],1); // Make stdout go to write end of pipe. - dup2( cp[1],2); // Make stderr go to write end of pipe. - close(0); // Close current stdin. - close( cp[0]); - - int ret = system(cmd); - +system_out(const char *cmd, const char **outbuf) +{ + // fprintf(out_stream,"system out\n"); + if (outbuf == NULL) { + return old_system_out(cmd); + } + + if (cmd == NULL) { + return -1; + } + + int cp[2]; // Child to parent pipe + + if( pipe(cp) < 0) { + return -1; + } + + pid_t pid = fork(); + if (pid == 0) { + //child + close(1); // Close current stdout./ + dup2( cp[1],1); // Make stdout go to write end of pipe. + dup2( cp[1],2); // Make stderr go to write end of pipe. + close(0); // Close current stdin. + close( cp[0]); + + int ret = 0; + if (execl("/bin/sh","sh","-c",cmd,NULL) == -1) { + ret = errno; + } close( cp[1]); - exit(WEXITSTATUS(ret)); + exit(ret); } else { - //parent + //parent char buf[1025]; memset(buf,'\0',1025); close(cp[1]); @@ -2577,16 +2577,14 @@ system_out(const char *cmd, const char **outbuf) strcat((char*)*outbuf,buf); } - //now wait on child to kick the bucket + //now wait on child to kick the bucket int status; wait(&status); close(cp[0]); - - return WEXITSTATUS(status); + return WEXITSTATUS(status); } } - /**********************************************************/ |