Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Im aware that i can get the output this way (to capture both standard and errors):

[batchFilePath] > [logFilePath] 2>&1

Or this way for standard output:

C:\MyBatchFile.bat > output.txt

But is there a way to do this without specifying the location of the batch file itself?

For example lets assume i run (just doubleclick to execute) C:\MyFolder\MyBatch.cmd and after i exit the batch file (or it completes) i can find the output in C:\MyFolder\MyBatch.txt

If so what code would i need to include in the batch file itself?

share|improve this question
up vote 2 down vote accepted

The only solution I can think of is adding >> output.txt at the end of every command outputing something of your batch file. It will add the output of your file at the end of output.txt

Or creating a second batch file which content would be .\MyBatchFile.bat > output.txt.

share|improve this answer
Thanks. I went with the second batch file option. – TMRW Jul 18 '13 at 17:44

Enclose your commands in round brackets. MyBatchFile.bat:

@echo off
REM setlocal enabledelayedexpansion
echo line one
echo line two
echo line three
) > "%~dpn0.txt"
share|improve this answer
thank you, saved me the hassle of having to create a wrapper – AdrianBR Aug 28 '14 at 10:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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