Results 1 to 1 of 1
I have the following piece of code to execute the pipe mechanism.
WHen i run this fucntion , it prints all the info in the line after the prompt and ...
- 10-12-2010 #1Just Joined!
- Join Date
- Oct 2010
- Posts
- 2
Printing issue in pipe
I have the following piece of code to execute the pipe mechanism.
WHen i run this fucntion , it prints all the info in the line after the prompt and not before the prompt.
Can someone help?
void executePipeFunctionality()
{
int fildes1[2];
int i = 0, index = 0, initIndex1 = 0, initIndex2 = 0, innerIndex = 0;
int j=0, k=0;
char* arg1[MAXITEM] = {NULL};
char* arg2[MAXITEM] = {NULL};
int returnValue = 0,status=0;
for(i=0;i<PIPE_ARRAY_INDEX;i++)
{
arg1[i] = (char*)malloc(sizeof(char) * strlen(GLOBAL_WORD_ARRAY[i]));
strcpy(arg1[i],GLOBAL_WORD_ARRAY[i]);
}
j=0;
for(i=PIPE_ARRAY_INDEX+1 ;i<INPUT_SIZE;i++)
{
arg2[j] = (char*)malloc(sizeof(char) * strlen(GLOBAL_WORD_ARRAY[i]));
strcpy(arg2[j],GLOBAL_WORD_ARRAY[i]);
j++;
}
if(fork()==0)
{
pipe(fildes1);
switch (fork()) {
case 0:
close(fildes1[1]); /* the other side of the pipe */
dup2(fildes1[0], 0); /* automatically closes previous fd 0 */
close(fildes1[0]); /* cleanup */
returnValue=execvp(arg2[0], arg2);
default:
close(fildes1[0]); /* the other side of the pipe */
dup2(fildes1[1], 1); /* automatically closes previous fd 1 */
close(fildes1[1]); /* cleanup */
returnValue=execvp(arg1[0], arg1);
}
}
else
{
wait(&status);
printf("-");
}
}


Reply With Quote