-1

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.

2
  • 1
    i'm fairly sure the command line as written doesn't work at all, as >%newFile% >&1is illegal. you meant to write >%newFile% 2>&1. Commented Dec 22, 2014 at 12:25
  • @ths i haven't tried this combination and it worked. Thanks ths!! Commented Dec 22, 2014 at 12:29

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.