Dsite42/minishell

cat | cat | ls

Closed this issue · 2 comments

jnspr commented

Should behave like this:

  • Press enter two times and you get back to your shell

Why it happens?

  • ls writes to STDOUT and exits, the read end of the pipe is closed
  • The user presses enter
  • The first cat writes \n to its write end of the pipe
  • The second cat reads it from the pipe
  • The second cat writes to its write end, but the read end has been closed because ls has exited already
  • The second cat exits aswell because write() returned zero or -1 (or it catches a SIGPIPE)
  • The user presses enter again
  • The first cat tries to write \n to the pipe but fails because the second cat exited aswell
  • The first cat exits and the user is thrown back to the prompt
jnspr commented

For n number of cats, enter has to be pressed n times

fixed it by change the else to else if: else if (piping_data->prev_read != STDIN_FILENO)
in file input_redirections.c