Now we are familiar with the command prompt. Batch scripts are written using a text editor. This does not mean Microsoft Word or Microsoft Works or any other of those fancy programs you might use to type up a report. Those types of programs are called word processors, not text editors. Besides the obvious that these programs allow you to change colors and import graphics, these programs add extra formatting that you don't see. A great example of a text editor is Notepad. Notepad comes bundled up with Microsoft operating systems. To access Notepad simply click the Start button followed by the Programs option. Next, click on Accessories which is usually at the top of the column. The next pop-up column should contain the Notepad program option.
A helpful hint is to make a shortcut to Notepad from your desktop by right-clicking on the Notepad option. Subsequently select Send To followed by selecting Desktop (Create a Shortcut). This allows quick access in the future by placing an icon on your desktop. A shortcut can also be made using batch. By the end of this article you will be able to create a short-cut in batch.
Now that we have Notepad open we can begin scripting. Let's begin by printing the words Hello World to the screen. Type the following into a Notepad screen. We want to save the file as helloworld.bat.
@Echo off
Rem helloworld.bat
:: Next line prints Hello World to the screen
Echo Hello World
PauseNow let's explain what each line does.
The computer has a habit of taking everything you type and storing it verbatim. This can be annoying and troublesome at first however you will soon realize that predictability is nice. Anyway, this means that all commands will be seen by the end-user. This makes for a very ugly and bothersome execution.
To circumvent this we will type @ECHO OFF at first line. ECHO OFF makes sure that command echoing is turned off. This fixes our previous problem. However, it creates a new one. ECHO OFF is a command thus it will be seen. That is where the use the @ sign comes in. This stops the echo of the ECHO OFF command. If you were to leave the @ sign out you would see ECHO OFF above your Hello World message as part of your output.
The majority of batch scripts have this snippet of code at the beginning. You can also turn echoing on if you like by using the command ECHO ON. If you type ECHO by itself the status of ECHO will be displayed. The ECHO OFF command only turns off command echoing. DOS commands will still be seen.
When you copy a file in a batch file, you will still see the 1 File(s) copied message. If you use a batch file to start a program that program will indeed appear on the screen. ECHO OFF turns off batch file commands while that specific batch file is running.
Please do not hesitate to contact our support department with any possible further questions or to solve practical issues connected with Command line email and batch files.