Friday, June 11, 2010

NOTEPAD HELLO BATCH COMMAND

Use Notepad to create a new file called hello.bat on your desktop. Add the code shown below to the file and save it.

This can be done step by step as follows:

· In the Start menu click: Programs – Accessories – Notepad

The Notepad program starts up showing an empty document with the title: “Untitled - Notepad

· In the Notepad menu click: File – Save As

The Save As dialog shows up

· In the Save As dialog use the Save in drop down box to select: Desktop

· In the File name field overwrite the file name by typing: hello.bat

· Click: Save

The Save As dialog will close. Notepad shows an empty document with the title: “hello.bat - Notepad”. A new icon with the name hello.bat appears on the Desktop.

· Type or copy/paste the following code into notepad:

@echo Hello world.

@pause

· In the Notepad menu choose: File - Save

Done! Your fist DOS batch file is ready to run.

· Minimize all windows and locate the icon called hello.bat on your desktop.

· Double click the hello.bat icon

A new window will open showing the following message:

Hello world.

Press any key to continue . . .

· Press any key, e.g. Space

The window will close.

Congrats

You just executed your first DOS batch.

4 Summary

When double clicking hello.bat on the desktop the file was passed to the DOS command processor. Independent from the executed batch file the command processor will always open a new window. This window will close when the command processor finished executing the batch file.

The command processor executes the commands listed in the batch file line by line. Commands in the batch file can instruct the command processor to interact with the user, i.e. to show some text output in the window or to wait fro keyboard input.

If not instructed differently the command processor echoes each command from the batch to the window before executing it. This can be useful for testing and debugging but is usually annoying in the final version of the batch file and because of this omitted in the example by having the ‘@’ sign in front of each line.

Inside Hello.bat


No comments:

Post a Comment