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 becausels
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 secondcat
exited aswell - The first
cat
exits and the user is thrown back to the prompt
jnspr commented
For n number of cat
s, enter has to be pressed n times
Dsite42 commented
fixed it by change the else to else if: else if (piping_data->prev_read != STDIN_FILENO)
in file input_redirections.c