Windows 7 / Getting Started

Command-Line Processing

The Command Prompt window prompts for commands one line at a time. In this section, describe how CMD interprets commands. Even if you are familiar with these concepts from MS-DOS, and even if you already know what > and < do, you should read through this section because there are several handy new features you might not yet know about.

CMD's most basic job is to read command lines that have this form:

programname arguments

Given this command, CMD tries to find an executable program file named programname. If it does find such a file, it instructs Windows to start the program. Any additional text typed on the command line-the command's arguments- are passed to that program to interpret. Of course, in practice, things aren't quite this simple:

  • CMD recognizes some built-in commands such as set and cls. For these, CMD doesn't search for a file but rather handles the command itself.
  • If the command isn't built in, CMD looks for a file named programname first in the current working directory, and then in a list of directories called the search path, which you can adjust.The default search path includes several of the subfolders under \WINDOWS. (Later in the tutorial, I show you how to modify the path to include your own folders.)
  • If you explicitly add a filename extension such as .EXE when you type the command, CMD looks through the search path only for this type of file. If you don't specify the file type, CMD looks for certain known file types.The list of file types is called the PATHEXT list, and you can modify the listed file types and their precedence if necessary.
  • When CMD has located a file matching the name of the command you typed, CMD looks at the file's extension to determine what to do with it. If the file has the extension .EXE or .COM, it's an executable program and is run directly. Files with the extensions .BAT and .CMD are taken to be batch files, and CMD interprets them itself.
    For any other file type, CMD uses the file association information from the Windows Registry to determine what to do. If the file type is associated with an application program, CMD starts the associated application to open the file. For example,WSH is used to run files with the extensions .VBS, .WSF, and .JS.
  • Many characters-including < > ( ) ; , | ^ & % and !-have special meaning to CMD and alter the interpretation of the command.We cover this topic shortly. After CMD has identified the program to run, it starts that program. If you've run a Windows program, it pops up on the screen and leaves the Command Prompt window free to do other things. If you've run a command-line program, it occupies the Command Prompt window until it completes or until you terminate it.

Stopping Runaway Programs

Occasionally you type a command that starts spewing page after page of text to the screen or one that displays some sort of ominous warning about making a change to Windows that can't be undone, and you want to stop it-pronto.

Most command-line programs quit if you press Ctrl+C. If that doesn't work, Ctrl+Break often works. As a last resort, you can simply close the Command Prompt window by clicking its close box in the upper-right corner.This kills the program in at most a few seconds.

You might also find the tasklist and taskkill command-line programs useful.

[Previous] [Contents] [Next]