News for hackers. Stuff that matters.
Re:What typing ^D does on Unix (2009) by kazinator on Tuesday September 06, 2016 @02:07PM (#12437974)
An important upshot is that TTY I/O never actually ends; EOF from a TTY is a temporary condition, and input can continue.

In the C standard library, you just clearerr(stdin) and keep reading.

If a program takes two files as input and obeys the - convention for specifying stdin (or has some other way of opening the tty more than once), you can do:

  $ program - -
then give it two inputs, each followed by [Ctrl-D][Enter]. For instance "cat - -".

This sort of thing subtly breaks with some utilities. Try coaxing GNU diff to compare two pieces of tty input, haha.

Re:What typing ^D does on Unix (2009) by philsnow on Tuesday September 06, 2016 @05:10PM (#12439320)
You can work around this with other shell trickery. This might work in your shell:

    $ program <(cat) <(cat)
The program itself isn't involved in opening the TTY / reading from it, etc, that is all handled by your shell before fork/execing program. program doesn't know that any of these shenanigans have happened.

It probably uses more memory (the shell has to have both stdin's in memory before it can exec the program), but overall I have mostly abandoned trying to use '-' as an input because of the way some tools, perhaps less-steeped in unix-y traditions, don't honor it correctly.