Hy. I want to create a program that uses the TEE command and instead of sending what I type to 1 file.txt, I want to make it send to 3 separate files. t1.txt and t2.txt are ok. But somewhere along the way I loose the info for t3.txt.
by the way TEE sends the STD_IN to STD_OUT and File (argument).
Can you point me in the right direction ?
Thanks
Code:
marktee()
{
pid_t pid;
int i;
int pi[2];
int fi[2];
int status;
pipe(pi);
pipe(fi);
for(i=0; i<2 && (pid=fork()); i++);
if(i==0 && pid==0)
{
printf("Child 1\n");
close(fi[0]);
dup2(pi[1],1);
close(pi[1]);
execlp("/usr/bin/tee","tee","t1.txt",0);
}
if(i==1 && pid==0)
{
printf("Child 2 \n");
//close(pi[1]);
close(fi[0]);
dup2(pi[0],0);
dup2(fi[1],1);
close(fi[1]);
execlp("/usr/bin/tee","tee","t2.txt",0);
}
else
{
printf("Parent\n");
close(pi[0]);
close(pi[1]);
close(fi[1]);
dup2(fi[0],0);
execl("/usr/bin/tee","tee","t3.txt",0);
wait(&status);
}