I would like to pipe standard output of a program while keeping it on screen.
With a simple example (echo
use here is just for illustration purpose) :
$ echo 'ee' | foo
ee
<- the output I would like to see
I know tee could copy stdout to file but that's not what I want.
$ echo 'ee' | tee output.txt | foo
I tried
$ echo 'ee' | tee /dev/stdout | foo
but it does not work since tee output to /dev/stdout
is piped to foo
Another thing to try is:
The
>(foo)
is a process substitution.Access to "/dev/stdout" is denied on some systems, but access to the user terminal is given by "/dev/tty". Using "wc" for "foo", the above examples work OK (on linux, OSX, etc.) as:
To add a count at the bottom of a list of matching files, I use something like:
% ls [A-J]* | tee /dev/tty | wc -l
To avoid having to remember all this, I define aliases:
% alias t tee /dev/tty
% alias wcl wc -l
so that I can simply say:
% ls [A-J]* | t | wcl
first you need to figure out the terminal associated with your screen (or whichever screen you want the output to display on):
then you can tee the output to that terminal and pipe the other copy through your foo program:
Try:
If using stderr is an option, of course.
Here is a solution that works at on any Unix / Linux implementation, assuming it cares to follow the
POSIX
standard. It works on some non Unix environments likecygwin
too.Reference: The Open Group Base Specifications Issue 7 IEEE Std 1003.1, 2013 Edition, §10.1: