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?

2 Answers 2


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.


Enclose your commands in round brackets. MyBatchFile.bat:

@echo off
REM setlocal enabledelayedexpansion

  echo line one
  echo line two
  echo line three
) > "%~dpn0.txt"

Variables inside the brackets are evaluated all at once when ( is encountered. Use enabledelayedexpansion to delay the evaluation.

  • 1
    thank you, saved me the hassle of having to create a wrapper
    – AdrianBR
    Aug 28, 2014 at 10:43

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.