Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void pipes(node_t *node)
- {
- debug();
- int pipefd[2];
- pid_t cpid1;
- pid_t cpid2;
- if (pipe(pipefd) == -1)
- {
- perror("pipe");
- _exit(EXIT_FAILURE);
- }
- cpid1 = fork();
- if (cpid1 == 0)
- {
- close(1);
- if(dup2(pipefd[1], 1) == -1) perror("dup2"); if(close(pipefd[1]) == -1) perror("close");
- close(pipefd[0]);
- if(execvp(node->pipe.parts[0]->command.program,node->pipe.parts[0]->command.argv)==0) perror("Error pipe");
- }
- else
- {
- cpid2 = fork();
- if (cpid2 == 0)
- {
- close(0);
- if(dup2(pipefd[0], 0) == -1) perror("dup2"); if(close(pipefd[0]) == -1) perror("close");
- close(pipefd[1]);
- if(execvp(node->pipe.parts[1]->command.program,node->pipe.parts[1]->command.argv)==0) perror("Error pipe");
- }
- else
- {
- exit(-1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement