Hi, I need to have one program Called Referee execute 2 other programs A and B that accept input with stdin and output to stdout. I need to be able to communicate with them and then close the pipe and the programs and execute a new set of programs in a cycle. Here is what I have right now. I am guessing it is wrong
Code:
pipe(p1Input); //input
pipe for A pipe(p1Output); //output pipe for A
if((pid = fork()) == - 1){ //fork referee
//Error
perror("There was an error creating a new process");
exit(0); }
else if(pid == 0){
//Child
dup2(p1Input[0], fileno(stdin)); //set the input to be stdin
close(p1Input[1]);//close the other end of the pipe
dup2(p1Output[1], fileno(stdout));//set the output to be out
close(p1Output[0]);//close the other end of the pipe
setvbuf(stdout,(char*)NULL,_IONBF,0); //not too sure if i ned hat
execl(argv[pOne], NULL);//execute A
}else{ //Parent
dup2(p1Input[1], fileno(stdout)); //set the output to be stdout
close(p1Input[0]); //close the other end of the pipe
dup2(p1Output[0], fileno(stdin)); //set the input to be stdin
close(p1Output[1]); //close the other end of the pipe
setvbuf(stdout,(char*)NULL,_IONBF,0); //not too sure if i need that
printf("INPUT\n");
//Now im not too sure how i would read what A is sending me.
wait(&status);
}
Sorry messed up had to reedit
Thank for your help