Windows 7 / Getting Started

Using the Prompt Command

The Prompt command changes the command line prompt. For example, instead of the usual drive letter, directory, and greater than sign, you could use the time and date as a prompt. In fact, the prompt can contain any text you want. To change the prompt, simply type Prompt, followed by the text you want to display, and press Enter. The following list defines the special characters you can use as part of the command prompt.

$A & (Ampersand)
$B | (Pipe)
$C ( (Left parenthesis)
$D Current date
$E Escape code (ASCII code 27)
$F ) (Right parenthesis)
$G > (Greater than sign)
$H Backspace (erases previous character)
$L < (Less than sign)
$N Current drive
$P Current drive and path
$Q = (Equals sign)
$S (Space)
$T Current time
$V Windows version number
$_ Carriage return and linefeed
$$ $ (Dollar sign)

You can access two additional formatting characters when you have command extensions enabled. The following list describes these two additions.

$+ Displays zero or more plus sign characters depending on the depth of the PushD utility directory stack. The display shows one character for each level you've pushed onto the stack.

$M Displays the remote name associated with the current drive letter. If this is a local drive, then the system displays an empty string.

Using the Rem Command

The Rem (Remark) command lets you add comments to your batch files. Given that batch files often use difficult to read coding sequences and that you'll probably want to modify them at some point, lots of comments are advisable. In fact, you'll want to add at least one comment for each complex line of code in your batch file. Many people have lost use of interesting and helpful batch files because they contain complex code that becomes unreadable after the initial writer forgets what the code means.

Using the Shift Command

A batch file supports a maximum of 10 command line arguments numbered %0 through %9. However, you might run into situations where you need more than 10 command line arguments. The Shift command can help you shift in these additional arguments. The new arguments replace existing arguments. In fact, all of the arguments are shifted one position, so the argument in %1 now appears in %0. Unfortunately, the argument in %0 is shifted out so that it's no longer accessible.

You can retain some older arguments in memory when you have command extensions enabled. The Shift command will accept a numeric argument that tells where to begin shifting arguments. For example, when the command appears as Shift /2, the values in %0 and %1 are unaffected. However, Shift will shift the arguments starting with %2 so that %2 now contains the value from %3.

Using the TimeOut Utility

The TimeOut utility provides a unique feature in that you can tell it to wait for a specified time period no matter what the user does. Consequently, unlike the Choice command, when you tell TimeOut to wait 30 seconds, it waits the entire time period even if the user presses a key. In addition, the TimeOut utility doesn't display a message for the timeout, so you can use this utility where silence is necessary (such as a background task). This command uses the following syntax:

TIMEOUT [/T] timeout [/NOBREAK]

The following list describes each of the command line arguments.

/T timeout Specifies the timeout value. The command line switch is optional. You may specify any value from -1 to 99999 seconds. A value of -1 means that the utility waits indefinitely for a key press. The utility won't allow you to combine a value of -1 with the /NOBREAK command line switch since that would effectively lock the system.

/NOBREAK Prevents the utility from recognizing key presses. The TimeOut utility waits for the specified time period before it exits.

[Previous] [Contents] [Next]