0

There is a ton of questions relating windows-redirecting, but I can't find anything on this (trivial?) behaviour.

I want to redirect some git-for-windows output into a file. Redirections like these work:

$ dir > test.txt
$ dir test > test.txt
$ ipconfig /all > t

est.txt

But this one outputs to the terminal and creates an empty file:

$ java -version > test.txt

This one outputs to a file correctly, but not if I invoke it from my IDE (which is IAR):

$ git --version > test.txt

The latest case is the one most interesting for me. How do I get the output of any executed program redirected into a file?

Janos
  • 796
  • 1
  • 9
  • 26
  • 1
    "java -version" goes to stderr. – 001 Nov 22 '16 at 16:24
  • *How do I get the output of any executed program redirected into a file?* - you don't. Both of those examples probably just write to `stderr` rather than `stdout`, but some programs really do write explicitly to the console. That's the programmer's decision. You can't override it. – Harry Johnston Nov 23 '16 at 01:25

1 Answers1

0

Try this way:

git --version > test.txt 2>&1

origin

Community
  • 1
  • 1
Soonts
  • 20,079
  • 9
  • 57
  • 130
  • Thanks, this one works for the `java -version`, as it apparently goes to `stderr`. `git --version` goes to `stdout`, as I can redirect it to a file when I invoke it directly. However, *both* redirections don't work, when I invoke the batch script from my IDE (IAR). It only creates an empty file `test.txt`. – Janos Nov 23 '16 at 08:38