6

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?

49

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

ipconfig /all > output.txt
  • 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 7: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 7: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 7: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 7:55
18

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.

  • 1
    Are you sure this usage is correct? It looks like nonsense, and it's undocumented in the Windows i/o redirection documentation. 2>>&1 does not take a file argument. For Powershell, ipconfig /all *>> logfile.txt is how you append all output streams 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
   [..]
  • 4
    While this is not a bad answer, putting MSYS2 in your path has surprising consequences. – Joshua Jan 16 '18 at 20:44
  • 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. – Mehrdad Jan 17 '18 at 8:53
  • 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 7: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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.