2

I would like to pipe standard output of a program that is running inside a docker container while keeping the output in the docker logs (i.e. stdout).

Another stackoverflow question (How to pipe stdout while keeping it on screen ? (and not to a output file)) suggests using foo | tee /dev/tty | bar, but this doesn't work when docker is run in non-interactive mode because /dev/tty doesn't exist.

Is this possible?

Oenotria
  • 1,692
  • 11
  • 24

1 Answers1

4

You want to duplicate the stdout of one program called foo to output it on your script stdout and pipe it to another program called bar. That's exactly what tee is for.

foo | tee >(bar)

If you don't have the shell that supports process substitution, you can do the same in a few more lines, by creating a fifo and running cat $fifo in background and running too "$fifo" to duplicate the stream to stdout and fifo:

fifo=$(mktemp -u); mkfifo $fifo;
cat "$fifo" &
foo | tee "$fifo" | bar
KamilCuk
  • 120,984
  • 8
  • 59
  • 111