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?

2
  • 2
    foo | tee >(bar) ? Commented Jun 24, 2018 at 10:57
  • This seems to work as long as I use bash instead of sh which is fine. Feel free to change this comment to an answer so I can tick it Commented Jun 24, 2018 at 11:20

1 Answer 1

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 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.