49

Does Windows provide the basic tee facility for copying standard input to an arbitrary set of files and then back out to standard output?

I generally download a generic tee program, but curious if something like this exists in powershell or something like that?

Jé Queue
  • 970

5 Answers5

47

PowerShell sure does, the cmdlet is called Tee-Object. You can also use the alias tee if you're more used to the Unix-like approach:

PS C:\Documents and Settings\Administrator> help Tee-Object

NAME
    Tee-Object

SYNOPSIS
    Saves command output in a file or variable and displays it in the console.

example:

C:>get-process | tee -filepath C:\file.txt

this will send the output to C:\file.txt as well as the console.

4

I just found a way to use the perl as alternative, e.g.:

CMD1 | perl -ne "print $_; print STDERR $_;" 2> OUTPUT.TEE
pegasus
  • 49
3

Native port of tee for Windows also exists, for example:

https://github.com/dEajL3kA/tee-win32/tree/master#tee-for-windows

lirisa8564
  • 31
  • 2
0

Use the native tee port from gnuwin32: https://gnuwin32.sourceforge.net/packages/coreutils.htm

0

For a cross-platform alternative, I use coreutils: https://github.com/uutils/coreutils (17k stars as of September 2024, 13k commits and updated daily)

Here is an example:

# Set the clipboard to "Hello World" and also save it as "hello_world.txt"
$ echo Hello World | coreutils tee "hello_world.txt" | clip
$ dir
2024.09.25  23:56                14 hello_world.txt
Doggo
  • 61