Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. static bool do_on_pipe(command_t *cmd1, command_t *cmd2, int level,
  2. command_t *father)
  3. {
  4. /* TODO redirect the output of cmd1 to the input of cmd2 */
  5. int exit_code = 0;
  6. int initial_in, initial_out;
  7. pid_t child1, child2;
  8. int pipe_fd[2];
  9. int status;
  10.  
  11. initial_in = dup(STDIN_FILENO);
  12. initial_out = dup(STDOUT_FILENO);
  13. pipe(pipe_fd);
  14.  
  15. child1 = fork();
  16. if (child1 == -1) {
  17. //eroare
  18. } else if (child1 == 0) {
  19. close(pipe_fd[0]);
  20. dup2(pipe_fd[1], STDOUT_FILENO);
  21. close(pipe_fd[1]);
  22.  
  23. exit_code = parse_command(cmd1, level + 1, cmd1);
  24. exit (-1);
  25. } else {
  26.  
  27. close(pipe_fd[1]);
  28. dup2(pipe_fd[0], STDIN_FILENO);
  29. //close(pide_fd[0]);
  30. exit_code = parse_command(cmd2, level + 1, cmd2);
  31. waitpid(child1, &status, 0);
  32.  
  33. dup2(initial_in, STDIN_FILENO);
  34. dup2(initial_out, STDOUT_FILENO);
  35.  
  36. close(initial_in);
  37. close(initial_out);
  38.  
  39. close(pipe_fd[0]);
  40. }
  41.  
  42. return exit_code;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement