46

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?

5
  • 6
    PowerShell is not for everyone so many will prefer to just download tee from unxutils.sourceforge.net
    – sorin
    May 5, 2010 at 21:47
  • 1
    What about cmd? I mean w/o downloading external tools is there a way to display the output of a program and write it into a file at the same time?
    – Nils
    Mar 7, 2012 at 13:43
  • 1
    powershell is for everyone from Vista and up
    – phuclv
    Mar 18, 2016 at 3:52
  • @phuclv, well except for anyone working in a corporation that just locks up the entire powershell functionality, which is almost all of them
    – Shodan
    Apr 5, 2023 at 6:28
  • @Shodan no most companies I know do not lock powershell at all. They may lock the ability to run powershell scripts but there's no way to completely prevent users from using powershell as an interactive tool
    – phuclv
    Apr 7, 2023 at 18:21

4 Answers 4

45

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.

5
  • There are also numerous ports of the original tee to Windows, but those can be easily found by one's favorite Internet search engine.
    – Joey
    Nov 23, 2009 at 8:39
  • Right, actually I "carry" a zip file with me from environment to environment; tee being part of that toolkit, but just a fundamentally useful facility I was thinking just HAD to be part of Windows somewhere.
    – Jé Queue
    Nov 23, 2009 at 16:06
  • 2
    The powershell tee isn't quite identical to the "UNIX / GNU" tee you are familiar with. I would very much recommend carrying around the UnxUtils with you and invoking them in this case.
    – Goyuix
    Jan 4, 2010 at 22:38
  • Thanks @joey, having ended up on this page while searching for tee for windows on a search engine
    – Shodan
    Apr 5, 2023 at 6:29
  • I can get it to work with some commands, but not with others. Weird... May 4, 2023 at 17:00
3

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

CMD1 | perl -ne "print $_; print STDERR $_;" 2> OUTPUT.TEE
3
  • 1
    The post seems to ask for a PowerShell solution. Perl doesn't work on Windows in a native fashion so.... hmmmm Jul 4, 2020 at 15:17
  • there's no perl in Windows by default
    – phuclv
    Apr 18, 2023 at 22:34
  • I have to make tee work on older Windows versions as well, where Tee-Object is not available. Not to mention that this works cross-platform if you replace the " with '. So this is a nice solution +1
    – Claudiu
    Mar 12 at 13:39
1

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

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

0

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

1
  • note to reviewers: I could not post this as a comment, as commenting is not allowed to new users Feb 16 at 9:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .