I fork()'d a child process and created pipes between them and am able to send argument argv[1] to the child. I want the child to take that filename provided from argv[1] and perform an execl("/bin/cat","cat",(char *) 0); How do I route the filename piped to the child to the execl?
Enclose is my code for clearity :
int main(int argc, char ** argv){
int fds[2];
char buffer[100];
int status;
if(pipe(fds) == -1){
perror("pipe creation failed");
exit(EXIT_FAILURE);
}
switch (fork()){
case 0://child
close(fds[1]); //close stdout so can only do stdin
read(fds[0],buffer,strlen(argv[1]));
printf("from parent: %s\n",argv[1]);
execl("/bin/cat","cat",(char*)0);
perror("cat failed");
exit(20);
break;
case -1: //fork failure
perror("fork failure");
exit(EXIT_FAILURE);
default: //parent
close(fds[0]); //close stdin so only can do stdout
write(fds[1],argv[1], strlen(argv[1]));
}
return (EXIT_SUCCESS);
}