Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

up vote 7 down vote accepted

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

share|improve this answer
    
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 '10 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 '10 at 14:37
1  
Excellent! thanks! I can't upvote here yet, not enough rep :( –  EJC Oct 12 '10 at 14:39
2  
No worries - you accepted the answer, and that's enough for me! :) –  Will Oct 12 '10 at 14:41
add comment

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

share|improve this answer
    
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 '10 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. –  Robert S Ciaccio Oct 12 '10 at 16:43
    
ok cool, I'll test this out shortly. Thanks for the tip. –  EJC Oct 12 '10 at 17:17
    
that's exactly what I needed :) –  Sherif Maher Eaid Jul 6 '12 at 16:21
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.