/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: dkaiser #include int main(void) { char *args1[] = {"/bin/cat", 0}; char *args2[] = {"/usr/bin/grep", "libft", 0}; int p[2]; pipe(p); pid_t pid = fork(); if (pid < 0) { exit(1); } if (pid == 0) { close(p[0]); int infd = open("in.txt", O_RDONLY); dup2(infd, 0); dup2(p[1], 1); execve(args1[0], args1, NULL); } else { wait(NULL); close(p[1]); dup2(p[0], 0); int outfd = open("out.txt", O_WRONLY); dup2(outfd, 1); execve(args2[0], args2, NULL); } }