#How does bash do this?

4 messages · Page 1 of 1 (latest)

trim ore
#

I need to code a simplified version of bash for a school project, and I'm struggling to recreate the behavior that bash has when inputted "cat | ls"
What happens is that the terminal displays the output for ls, and then lets you enter one line.
I think this is because ls doesn't need to read from cat, and therefore it doesn't wait for it to be finished, so as soon as cat reads one line it tries writing it into ls's input, and since that it is closed, it fails and exits.

I tried emulating this by creating a pipe, forking my main process, duping the write end, executing cat, forking again, duping the read end, executing ls, then waiting for cat, then waiting for ls.

Unfortunately this doesn't seem to work, as cat goes on until i terminate it with a signal, or it reaches EOF.

How does bash handle this to get that result?
What should I do?

misty coralBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

trim ore
#

solved, i was helped by people at school

#

!solved