Search code examples
batch-filefile-iobatch-rename

Windows batch renaming print commands + errors to txt


I've generated a batch file that's a long list of ren "x.jpg" "y.jpg" type commands.

I'd like to have all of the results outputted to a .txt file, but when I've tried to cmd rename.bat > output.txt or rename.bat >> output.txt, it only prints the command performed and not if there was an error in finding file, which instead shows in the cmd window.

How can I have all of it put into the .txt file?


Solution

  • When running this batch script from cmd, you can use:

    script.bat > output.txt 2>&1
    

    This will direct stdout to output.txt and stderr to redirect to stdout (thus appending the errors to the file). Essentially, this will give you exactly what you would normally see at the console when running the script.