Tech: Directing screen output to file with MS-DOS batching

How do you capture an error message from an MS-DOS prompt to a file?

One easy way would be to copy and paste it manually.

  • Right-click, select Mark and highlight the text.
  • Right-click again to copy.
  • Right-click to paste in the DOS prompt window, or Control-V to paste in other screens.

What if we wanted to use a batch file (.bat) to capture the output of several different commands at one go?

Use this:

cd K: >test.txt 2>&1

This example attempts to change directory to K: (which doesn’t exist), so the resulting error message is written to test.txt instead.

Thanks to YH for asking the question on Facebook, and I hope this tip helps some other lost soul out there.

Advertisements