Home > Articles > Home & Office Computing > Microsoft Windows Desktop

  • Print
  • + Share This
This chapter is from the book

Displaying Information in Batch Files

By default, batch files display or echo every line inside them to the Command Prompt window as they run. For complex batch files, this can be very distracting, as page after page of commands and messages scroll by. It's hard to read, and you may miss important error messages buried in the middle of the mess. Therefore, it's traditional to disable batch file echoing with the statement

@echo off 

at the very beginning of the file. Echo off turns off the echoing feature, and the @ at the beginning of the command prevents the echo command itself from being echoed before it can work its magic.

However, it's nice to have batch files tell you what's going on inside so that you'll know that something is actually happening. The echo command is great for this—it echoes whatever text follows the word echo, so you can throw helpful comments throughout the batch file like this:

@echo off 
echo Starting to sort files...
.
.
.
echo Sending results to the printer...
.
.
.
echo Done.

You can also have echo commands display the environment variables and command-line arguments with which the program is working. For example,

echo Your user name is %username% 

will print Your user name is followed by the contents of the username environment variable. I'll show examples of this kind of informational message throughout the chapter.

  • + Share This
  • 🔖 Save To Your Account