How to pipe output and duplicate it to STDOUT? [duplicate]

How can I pipe the output of one program to another, but also have it appear on screen.

For example, to duplicate what winds up on the clipboard in dir | clip, or to see what's happening along the way in longer chains.


Solution 1:

If you have a copy of tee that runs on Windows, such that dir | tee NUL | clip loads the clipboard, but doesn't display anything on the screen (behaving as you would expect dir | clip to), try dir | tee con | clip.  (con is short for “console”; it’s Windows’ equivalent of /dev/ttynul, naturally, is Windows’ equivalent of /dev/null.)

Solution 2:

In Linux you have got tee: Wikipedia - tee. You could install GNU core-utils for Windows: http://gnuwin32.sourceforge.net/packages/coreutils.htm

Example:

dir | tee clip

Should work just fine but I don't have Windows to try right now.

EDIT:

Another program - wintee You don't have to install coreutils (which I would advise to install anyway).