Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static bool do_on_pipe(command_t *cmd1, command_t *cmd2, int level,
- command_t *father)
- {
- /* TODO redirect the output of cmd1 to the input of cmd2 */
- int exit_code = 0;
- int initial_in, initial_out;
- pid_t child1, child2;
- int pipe_fd[2];
- int status;
- initial_in = dup(STDIN_FILENO);
- initial_out = dup(STDOUT_FILENO);
- pipe(pipe_fd);
- child1 = fork();
- if (child1 == -1) {
- //eroare
- } else if (child1 == 0) {
- close(pipe_fd[0]);
- dup2(pipe_fd[1], STDOUT_FILENO);
- close(pipe_fd[1]);
- exit_code = parse_command(cmd1, level + 1, cmd1);
- exit (-1);
- } else {
- close(pipe_fd[1]);
- dup2(pipe_fd[0], STDIN_FILENO);
- //close(pide_fd[0]);
- exit_code = parse_command(cmd2, level + 1, cmd2);
- waitpid(child1, &status, 0);
- dup2(initial_in, STDIN_FILENO);
- dup2(initial_out, STDOUT_FILENO);
- close(initial_in);
- close(initial_out);
- close(pipe_fd[0]);
- }
- return exit_code;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement