9

I want to save ipconfig /all to text file.I am on Windows 10.When I try this in cmd

ipconfig /all | tee file.txt

I got

'tee' is not recognized as an internal or external command,operable program or batch file.

What is Windows alternative for tee?

blahdiblah
  • 4,873
  • 2
  • 22
  • 30
MikiBelavista
  • 459
  • 1
  • 5
  • 18
  • 8
    I suggest removing `powershell` as a tag in your question, as `ipconfig /all | tee file.txt` is a valid PowerShell command and works exactly as you expect it to. `tee` is an alias for `Tee-Object`. – davidmneedham Jan 16 '18 at 15:26
  • 13
    For what its worth, tee is never needed to save output to a file - that's just so you can see the output _and_ save it to a file. – JPhi1618 Jan 16 '18 at 22:40
  • Should you wish to output to say display and to file, there is a Windows version of tee called wintee : https://code.google.com/archive/p/wintee/ – Dimblefeck Jan 17 '18 at 16:20
  • @Dimblefeck there are so many tee implementations for Windows like gnuwin32 tee and windows also have a native one in powershell – phuclv Jan 18 '18 at 07:53
  • so many duplicates: [tee for Windows?](https://superuser.com/q/74127/241386), [How can I both pipe and display output in Windows' command line?](https://superuser.com/q/767680/241386), [How to redirect output to a text file and the console (cmd) window at the same time?](https://superuser.com/q/109953/241386) – phuclv Jan 18 '18 at 07:57
  • Possible duplicate of [Windows: Command line redirection to text file while also seeing output](https://superuser.com/questions/278115/windows-command-line-redirection-to-text-file-while-also-seeing-output) – phuclv Jan 18 '18 at 07:57

3 Answers3

51

Try redirection. Instead of | tee, use > output.txt e.g.

ipconfig /all > output.txt
Richard
  • 5,831
  • 9
  • 44
  • 73
Greg W
  • 1,123
  • 10
  • 8
  • 1
    redirection doesn't work like tee. You need to print the file afterwards like `ipconfig /all > output.txt & type output.txt`, but it still won't behave like tee which outputs immediately – phuclv Jan 18 '18 at 07:45
  • This question is tagged "cmd.exe" and not "PowerShell". There is no equivalent for tee in cmd.exe. There is however, Tee-Object in PowerShell, which has tee as an alias. – Greg W Jan 18 '18 at 07:50
  • yes, but your answer **doesn't answer what the OP wants**, which is **putting output in both stdout and file** – phuclv Jan 18 '18 at 07:52
  • 10
    The question title specifically states "HOW TO SAVE IPCONFIG OUTPUT TO A TEXT FILE WHEN TEE IS NOT AVAILABLE". There is no mention in the question title, nor the body, of displaying the content to the screen simultaneously other than a reference to the tee command itself. – Greg W Jan 18 '18 at 07:55
19

ipconfig /all >>logfile.txt 2>>&1

The >>logfile.txt 2>>&1 will redirect both output stream and error stream to a file called logfile.txt that will be created and stored in the current directory. If there is an existing logfile.txt in that directory it will append the output to the end of it.

Ciaran McKenzie
  • 433
  • 2
  • 12
  • 1
    Are you **sure** this usage is correct? It looks like nonsense, and it's undocumented in the [Windows i/o redirection documentation](https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true). `2>>&1` does not take a file argument. For Powershell, `ipconfig /all *>> logfile.txt` is how you [append all output streams](https://stackoverflow.com/a/41148807/699305) to a file. – alexis Jan 17 '18 at 16:42
  • 1
    Did you mean `ipconfig /all >> logfile.txt 2>&1` perhaps? – A C Jan 17 '18 at 22:54
  • I'm surprised my mistake went without being pointed out for this long, indeed I was a little bit off as I just quickly checked a .bat file I had it in myself and misread it at a glance. I have edited my answer to the correct usage, apologies! – Ciaran McKenzie Jan 18 '18 at 11:44
8

If you install MSYS2 you can use

$ ipconfig -all | tee file.txt

Note that /all has to be written as -all.

In my case I get:

$ head file.txt

Windows-IP-Konfiguration

   Hostname  . . . . . . . . . . . . : Death-Star
   [..]
mvw
  • 851
  • 5
  • 12
  • 4
    While this is not a bad answer, putting MSYS2 in your path has surprising consequences. – Joshua Jan 16 '18 at 20:44
  • If you don't like MSYS, there's GnuWin32. The `tee` utility is under [GnuWin32 core utils](http://gnuwin32.sourceforge.net/packages/coreutils.htm). – JimB Jan 16 '18 at 21:16
  • 1
    @JimB: MSYS wasn't great, so GnuWin32 was a good alternative for it, but MSYS2 has been excellent as far as I've tried it. I do not know of any reason to use GnuWin32 over it. – user541686 Jan 17 '18 at 08:53
  • @Joshua: What are the consequences? I just put it after the normal stuff and it works fine? – user541686 Jan 17 '18 at 08:54
  • 1
    @Mehrdad: Some of that stuff expects other stuff provided by it to be early in the path. I haven't tried to catalog all the cases but eventually you discover you have two `find` commands that do different things. – Joshua Jan 17 '18 at 14:58
  • 2
    no need for msys2. `powershell -command "ipconfig /all | tee output.txt"` will work if you're in cmd – phuclv Jan 18 '18 at 07:48
  • 1
    @LưuVĩnhPhúc make an answer of your proposal, it is by far and wide the very best solution! – user2531336 Jan 18 '18 at 10:18