Windows – Dump contents of a cmd prompt into a file, from a batch file

batch filecommand linewindows

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.

Best Answer

  • 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