Pipe stdout of two programs to each other

Solution 1:

Create a named FIFO that will "loop" the pipe:

mkfifo myfifo
<myfifo program1 | program2 >myfifo
rm myfifo

Even if none of the programs prints anything first, you can "inject" data into the FIFO, so it's received by program1:

# from another console
echo start >myfifo

To observe/store the communication, use tee in the right place(s). Examples:

<myfifo program1 | program2 | tee myfifo
<myfifo program1 | tee /dev/tty ./log1 | program2 | tee ./log2 >myfifo

The whole thing will work in sh, there's nothing specific to Bash in this solution.

Please read this answer about possible scenarios leading to a deadlock.