Archive for CMD Forums The unnofficial forum about the console-based elements of windows.

CMD Forums Forum Index -> Batch (Windows NT Command) Files admin *.CMD Files Tutorial 1: The Basics

I strongly recommend to anyone planning to make a batch file that they use the *.CMD type name. This is because this way only modern PCs with the right commands from the CMD.EXE program will be able to use it and any computers reliant on COMMAND.COM and other commands won't be able to run it so there won't be any trouble caused by the use of modern commands unknown to the likes of DOS-based PCs. In short, if a PC can't run a CMD file, it can't run the commands in it anyway. It helps a lot if you're familiar with using CMD.EXE. The command prompt is a text-based console program that works like the legacy that was COMMAND.COM and MS-DOS. CMD.EXE is able to do a lot more than MS-DOS could and it is actually a lot easier to use. There were a lot of stupid rules in MS-DOS that don't exist in the 32-bit CMD.EXE. An example of this is that you can have filenames longer than 8 characters with a 3 letter extension and you can specify whether the letters are upper/lower-case. A batch file is simply a list of commands which are executed line-by-line. The only problem for someone that's used to CMD.EXE and not batch files is that you tend to use different commands for the batch process as well as the usual ones in order to make it run as desired. Now, to make your first *.CMD file, open NOTEPAD.EXE and enter:
Code: @ E C H OO F F E C H O . H e l l ow o r l d . P A U S E E C H OO N

and save it as HelloWorld.CMD. Then open it up to see what happens. You will get:
Code: H e l l oW o r l d . P r e s sa n yk e yt oc o n t i n u e . . . _

I shall explain what caused all this. The ECHO command changes whether or not you can see the prompt, and can also print output to the screen. ECHO OFF will turn off the prompt so that our batch file doesn't get messed up with all that 'C:\WINDOWS\system32>_' rubbish. Then is the ECHO.Hello world. command. If a full-stop ('.') is inserted straight after the ECHO part then it will print output to the screen, in this case 'Hello World.' to the first line. Then it moves to the PAUSE command which on the next line adds a 'Press any key to continue..._' to the screen which is a pretty self-explanetary command. For more info on these commands try entering "CD /?", "ECHO /?", or "PAUSE /?" into the CMD.EXE. The last line has 'ECHO ON' which turns the prompt back on just in-case the thing after the batch program has run wants to have the prompt back (which is responsible batch behaviour, like picking up rubbish and litter in real-life). On the first command there is an '@' symbol. This is to stop the prompt being shown for this command because until that command has been executed, the prompt is

still shown. CMD Forums Forum Index -> Batch (Windows NT Command) Files Page 1 of 1 Create your own free forum | Buy a domain to use with your forum .