So, I have this batch file that runs every morning at 7 AM and does some work in a Windows command prompt.

What I need this batch to also do is save the output of the cmd prompt work that was done into a text file so I can view its status. If the batch fails it's not critical, but I need to know about it.

If I could print the contents of the cmd prompt to a text file or email myself the results of the run that would be awesome.

3 Answers 3


You just need to add this to the end of whatever runs the batch file: > "c:\yourFile.txt"

(or >> "c:\yourFile.txt" if you want the results appended to the file without overwriting)

eg: c:\yourBatchFile.bat >> c:\yourLogFile.txt

  • sweet. is there a way to append like the date to the filename, so it creates a new file everyday? It's too much output to append...
    – EJC
    Oct 12, 2010 at 14:33
  • 2
    Sure - just set up a variable with the format you like and use it in the filename- take a look at this article for a quickstart
    – Will
    Oct 12, 2010 at 14:37
  • 1
    Excellent! thanks! I can't upvote here yet, not enough rep :(
    – EJC
    Oct 12, 2010 at 14:39

FYI... just using the greater-than like in the other answers won't capture error output, only stdout... So any errors would still go to the command line display and not to your log file and you still would not be informed of any failures.

For both stdout and stderr you need this syntax:

[batchFilePath] > [logFilePath] 2>&1

  • Cool thanks. The errors I'm worried about are errors in the programs that are running, which I usually read on the cmd prompt when they happen, not errors in the batch itself. I guess I never thought I should be worried about batch errors themselves. I'm doing an svn update building the code every morning before i get to work. I just need to know if there were any conflicts, or build errors so i can fix them if necessary.
    – EJC
    Oct 12, 2010 at 16:41
  • 1
    right, but the programs themselves normally write to stderr when they fail as well, depending on how they were coded. svn and most compilers definitely write to stderr. so if you don't use that syntax, the program errors won't end up in the log file either. Oct 12, 2010 at 16:43
  • ok cool, I'll test this out shortly. Thanks for the tip.
    – EJC
    Oct 12, 2010 at 17:17
  • that's exactly what I needed :)
    – smohamed
    Jul 6, 2012 at 16:21

Try redirecting the output by putting ">" and a filename after the scheduled command, as in:

C:\MyBatchFile.bat > output.txt

Putting two ">", as in ">>", will append instead of overwriting.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .