- The writing process (
echoin your case) is not oblidged to write anything to its stdout (for instance,echo -nwould not write anything to its stdout and exit successfully). - It's also able to make arbitrary delays writing its data (either because it wants to make such delays or because it has been preempted by the OS or sleeps in some syscall waiting on some busy system resource etc).
- The OS buffers transfers over pipesOS buffers transfers over pipes, and often the code in the program does this, too—though it may not be apparent for an inexperienced programmer. ThisThis means what the writing process sends to a pipe, might come out in arbitrary chunks on the reading side.1
- There are only two ways to know the writing side has no more data to send over the pipe:
- Somehow encode this in the data itself (this means using an agreed upon data transfer protocol between the writer and the reader).
- The writer might close its side of the pipe which would result in the "end of file" condition on the reader side (but only after the buffer is drained and one another call to
readis attempted, which fails).
that would not meant the spawned process would not have stdin (or "initial stdin" or whaveter), instead, its stdin would be connected to the same stream your shell receives your keyboard importinput from (so you could directly type something to your process's stdin).