Hey Guys,

At work we are trying to move from unix to linux. In one of our program we call the util or routine captureout. It takes from the command line specific information and pipes the input and then the output back to a buffer variable. It used to work in unix but now when we run the same thing in linux it doesnt work. I tried to output the buffer and I would get a random number like 9.1e31. I was wondering if you guys knew a solution to this. Ill post the function that I am having the problem with.

int captureout(char *command, char buffer[]) {
int defaultin; /* default stdin channel */
int defaultout; /* default stdout channel */
int defaulterr; /* default stderr channel */
int fdpipe[2]; /* file descriptor pipe */
char path_command[200]; /* command string with path */

defaultin = dup(0); /* defaultin now points to the stdin */
defaultout = dup(1); /* defaultout now points to the stdout */
defaulterr = dup(2); /* defaulterr now points to the stderr */

/* create a pipe to be used to redirect the output */
if (pipe(fdpipe) == -1) {
fprintf(stderr, "VERIFY Error: not enough resource to allocate pipes\n");
return 0;
}

/* accept input from the stdin */
dup2(defaultin, 0);
/* redirect the output to the pipe */
dup2(fdpipe[1], 1);
/* display error via the stderr */
dup2(defaultout, 2);

//sprintf(path_command, "/home/tlabat-2/hzhang/FP9.0/omniber/%s", command);

sprintf(path_command, "/vobs/SIT5500/TOOLS/GPIB/bin/%s", command);

/* execute the command
At this point, output captured will be redirected to the pipe */
system(path_command);

//printf("PATH Command == %s\n", path_command);
/* Obtain the output from the previous command via the pipe */
dup2(fdpipe[0], 0);

/* redirect the output to the stdin */
dup2(defaultout, 1);

// printf("Defaultout = %s\n", defaultout);
/* piped output is read as though they were typed via keyboard */
gets(buffer);
// printf("Buffer is = %s\n", buffer);


/* clean up */
close(fdpipe[0]);
close(fdpipe[1]);
close(defaultin);
close(defaultout);
close(defaulterr);

return 1;
}

If you find any solution thanks.