Using the CMD Switches
The command interpreter, CMD.EXE, is the most important part of the command line because it affects everything you do at the command line. A small change in the command interpreter can make a significant change in the way your applications run. The default command prompt setup assumes that you don't want to use any of the command line switches and that you want to start in your home directory.
If you used the Disk Operating System (DOS) at some point, it's important to remember that the command line switches that Windows supplies for the CMD.EXE command interpreter in no way match what you used in the past. Microsoft does make some command line switches available for compatibility purposes. For example, the /X command line switch is the same as /E:ON, /Y is the same as /E:OFF, and /R is the same as /C . The command interpreter ignores all other old switches; you need to use the command line switches described in this section instead.
You might also remember a few convenience features from the days of DOS that no longer appear as part of Windows. For example, at one time you could create a setup menu by using the [MENU] entry in Config.SYS. The Config.NT file doesn't support this setup. The only alternative is to create multiple Config.NT files and assign them to applications as needed. In short, even though the command interpreter does many of the same things that the DOS version does, this command interpreter is different and you need to proceed with caution about any assumptions you want to make. This application uses the following syntax:
CMD [{/A | /U}] [/Q] [/D] [/E:{ON | OFF}] [/F:{ON | OFF}] [/V:{ON |
OFF}] [[/S] [{/C | /K}] string] [/T:FG]
The following list describes each of the command line arguments.
/C string Performs the command specified by string and then terminates the command interpreter session. Generally, you won't get to see any application output using this technique unless the application provides graphical output or you use redirection to save the results in a file.
Note: When using either the /C or /K command line switches, you can specify multiple commands by creating a single string that contains all of the commands. Separate each command using a double ampersand (&&). You must enclose the entire string in double quotes. For example, "Dir *.DOC&&Dir *.TXT" would perform two Dir commands. The first would search for any file with a DOC extension, while the second would search for any file with a TXT extension.
/K string Performs the command specified by string. The command window remains after execution ends so that you can see the application results.
/S Modifies the treatment of the command string used with the /C and /K command line switches. The command interpreter provides two methods for processing the command string. When you use the /S command line switch, the command processor views the string associated with the /C and /K command line switch. It verifies that the first character is a quote and removes it from the string. The command processor then looks for the closing quote and removes it as well. You can use this option when the presence of quotes causes problems executing the command. The command interpreter also strips the quotations marks when you:
- Use any of the following special characters within the string: & < >( ) @ ^ |
- Include one or more white space characters
- Include an executable filename as part of the string
- Use more than one set of quotes in the string
/Q Turns off echo. Echo is the output of the command interpreter that tells you which command is running.
/D Disables the execution of AutoRun commands from the registry. This registry entry appears later in this section of the tutorial.
/A Specifies the output of internal commands to a pipe or file using American National Standards Institute (ANSI) characters.
/U Specifies the output of internal commands to a pipe or file using Unicode characters.
/E:ON Enables the command extensions. The command extensions provide added functionality for these commands: Assoc, Call, ChDir (CD), Color, Del (Erase), EndLocal, For, FType, GoTo, If, MkDir (MD), PopD, Prompt, PushD, Set, SetLocal, Shift, and Start (also includes changes to external command processes). The "Understanding Command Extensions" section of the tutorial tells you how the command extensions affect these commands.
Note: You might notice that some commands appear in parentheses. For example, the ChDir command appears before the (CD) command in parentheses. The two commands are equivalent. You can use whichever form you want. The parentheses don't show a preference, simply an alternative.
/E:OFF Disables command extensions.
/F:ON Enables file and directory name completion characters. File and directory completion allow speed typing at the command line. For example, if you want to type Dir Temp, using directory or file completion, you could type Dir T, and then press Ctrl+D (for a directory) or Ctrl+F (for a file). The command interpreter automatically completes the directory or filename for you. If you type in a partition string that doesn't match any entries, the command interpreter beeps to signify that the entry is incorrect. When the command interpreter sees multiple entries that could match the entry you provide, it displays the first entry in the list. You cycle through the entries by pressing Ctrl+D or Ctrl+F again. Use the Shift+Ctrl+D and Shift+Ctrl+F control key combinations to move backward through the list of choices. You can change the control characters that this feature uses by changing the associated registry entry. You must enclose any file or directory names that begin with special characters in quotes. These characters include <space> & ( ) [ ] { } ^ = ; ! ' + , ` ~.
/F:OFF Disables file and directory name completion characters (see the /F:ON command line switch for details).
/V:ON Enables delayed environment variable expansion. The expansion relies on the exclamation mark (!) as the delimiter. Consequently, supplying !MyVar! at the command line would expand (display the value of) MyVar at execution time.
/V:OFF Disables delayed environment variable expansion.
Note: Vista and Server Core continue to support the /T command line switch, even though it doesn't appear with the CMD executable help. It's important to realize that Microsoft often gets rid of undocumented command line switches, so you might not have access to this feature in a future release.
/T:FG Sets the foreground (F) and background (G) colors. You must place the values together, without any space between. The following list tells you which colors you can use at the command prompt, along with their associated color number.
0-Black 1-Blue 2-Green 3-Aqua 4-Red 5-Purple 6-Yellow 7-White 8-Gray 9-Light blue A-Light green B-Light aqua C-Light red D-Light purple E-Light yellow F-Bright white
Combine the command line interpreter with the Start command to create additional windows as you need them. To create an additional basic command interpreter, type Start /Separate CMD.EXE and press Enter. Notice the positioning of the /Separate command line switch-it belongs to Start, so you place it with Start. If you wanted to create a new command line interpreter with a blue background and green lettering, you'd type Start /Separate CMD.EXE /T:1A and press Enter. Again, notice the positioning of the /T command line switch-it belongs to CMD.EXE, so you place it there. When you finish using the new command line interpreter, type Exit and press Enter.
In this tutorial:
- CMD and BAT Files
- Starting the Command Interpreter
- Using the CMD Switches
- Working with the Command Interpreter in the Registry
- Modifying Config.NT
- Displaying the Config.NT Commands
- Modifying AutoExec.NT
- Saving Memory Using the LH Command
- Defining Application Compatibility with the SetVer Utility
- Using Common DOS Utilities
- Formatting a Disk with the Format Utility
- Terminating a Session Using the Logoff Utility
- Managing Environment Variables with the Set Command
- Managing Environment Variables with the SetX Utility
- Using Debugging Utilities
- Working at the Command Prompt
- Managing Usernames and Passwords with CmdKey
- Changing Screen Colors with the Color Command
- Obtaining Command Line Help with the Help Utility
- Creating Batch Files
- Using the Choice Command
- Using the For Command
- Using the Goto Command
- Using the Prompt Command
- Using the WaitFor Utility