Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/wait.h>
- #include <sys/types.h>
- int
- main(int argc, char *argv[])
- {
- int fdp[2];
- pipe(fdp);
- int status;
- if (fork() == 0) {
- pid_t pid;
- if ((pid = fork()) == 0) {
- int in = open(argv[4], O_RDONLY);
- close(fdp[0]);
- dup2(in, 0);
- dup2(fdp[1], 1);
- close(in);
- execlp(argv[1], argv[1], NULL);
- _exit(1);
- }
- waitpid(pid, &status, 0);
- if (WIFEXITED(status) && !WEXITSTATUS(status)) {
- if (fork() == 0) {
- close(fdp[0]);
- dup2(fdp[1], 1);
- execlp(argv[2], argv[2], NULL);
- _exit(1);
- }
- }
- _exit(0);
- }
- close(fdp[1]);
- if (fork() == 0) {
- int out = open(argv[5], O_WRONLY | O_CREAT | O_APPEND, 0660);
- dup2(fdp[0], 0);
- dup2(out, 1);
- close(out);
- execlp(argv[3], argv[3], NULL);
- _exit(1);
- }
- close(fdp[0]);
- while (wait(NULL) != -1) {}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement