Q: process exits after getting command from pipe On Ubuntu, I start a command line program (gnu backgammon) and let it get its commands from a pipe (commandpipe), like so
$ gnubg -t < commandpipe

from another terminal, I do
$ echo "new game" > commandpipe

This works fine, a new game is started, but after the program has finished processing that command, the process exits. 
How can I prevent the backgammon process from exiting? I would like to continue sending commands to it via the commandpipe.

A: This is only because you used echo, which immediately quits after echoing. I believe when a program quits its file descriptors are closed. (OK, it's not an actual program in bash, it's a builtin, but I don't think this matters.) If you wrote an actual interactive program, e.g. with a GUI (and remember, StackOverflow is for programming questions, not Unix questions, which belong over there) and redirected its stdout to the named pipe, you would not have this problem.

A: The reader gets EOF and thus closes the FIFO. So you need a loop, like this:
$ while (true); do cat myfifo; done | ts
jan 05 23:01:56 a
jan 05 23:01:58 b

And in another terminal:
$ echo a > myfifo 
$ echo b > myfifo 

Substitute ts with gnubg -t

A: The problem is that the file descriptor is closed, and when the last write file descriptor is closed, it sends a signal to the read process.
As a quick hack, you can do this:
cat < z  # read process in one terminal
cat > z &  # Keep write File Descriptor open. Put in background (or run in new terminal)
echo hi > z  # This will close the FD, but not signal the end of input

But you should really be writing in a real programming language where you can control your file descriptors.

A: To avoid EOF, you could use tail:
tail -f commandpipe | gnubg -t 

