0

I am trying to call a command in batch file using "call" method and whatever is the output of that command, I want to write in a file. I went through from this link but cannot find the answer.

I am using this command

call %confPath% GetIniString %datFile% Keyname name >%newFile% >&1

but it creates a empty file always. How can i write the output of above command in the file?

Thanks in advance.

Community
  • 1
  • 1
Tarun Sharma
  • 601
  • 3
  • 13
  • 31
  • 1
    i'm fairly sure the command line as written doesn't work at all, as `>%newFile% >&1`is illegal. you meant to write `>%newFile% 2>&1`. – ths Dec 22 '14 at 12:25
  • @ths i haven't tried this combination and it worked. Thanks ths!! – Tarun Sharma Dec 22 '14 at 12:29

1 Answers1

1

>%newFile% redirects the standard output to a file. in >&1, the 1 stands for standard output, and if no stream is specified, standard output is the default, so >&1 redirects on itself, although it was already redirected with the first command. So, this is illegal and shouldn't produce a file at all. In my tests, this just aborts with an errormessage.

The usual idiom 2>&1, OTOH, redirects stream 2, which is standard ERROR, to standard output, which ensures that both output and error messages end up in the file.

ths
  • 2,858
  • 1
  • 16
  • 21