Work in progress

COMMAND.COM Internal Commands

These differ from Intrinsic Batch Commands and Statements in that they are also available from the command line (though some of the latter are as well, but are seldom used that way).


Useful things you can do with the PROMPT

There are two categories of things to do with the PROMPT command: issue strings containing hard to deal with Escape characters to the console and obtain information for use in the batch file (or elsewhere). The former is most frequently used to send ANSI Escape sequences to ANSI.SYS (a replacement console device). This is easy:

 @echo off
 set oldprompt=%prompt%
 prompt $e[2J
 echo on

 @echo off
 set prompt=%oldprompt%
 set oldprompt=
 :end
clears the screen. The Escape sequences are more often used to control colors and/or cursor position, though - just change the part after "$e[" to whatever you need.

Since we want the changed prompt to be active only once, we save the old string, turn echoing on, generate a pure prompt with a blank line, then turn echoing off again, and restore the original prompt string.

Using the prompt to get information is a bit trickier, since we have to redirect the prompt into a file, and that can't be done, except by spawning a secondary command processor and redirecting its output, which leaves us with the problem of getting the information back into the program:


 @echo off
 %1 %2
 set oldprompt=%prompt%
 prompt %0 goto pass2 $d $t
 command /c%0 goto dummy > }{.bat
 set prompt=%oldprompt%
 set oldprompt=
 }{
 goto end
 :pass2
 set stamp=%4/%5
 goto end
 :dummy
 echo on

 @echo off
 :end
generates a date/time stamp of the form 09-09-1995/19:39:05.29 (you could strip off just the characters form the time that you wanted with some of the string processing code found in many of the examples here and elsewhere in this book. Note that %3 is omitted from the stamp: it is the day name.

The problem of getting the information back into the batch file is dealt with here by including the necessary commands to reinvoke the batch file and vector it to the proper section of code in the changed prompt string, and therefore in the batch file that the prompt is redirected to. The invocation of COMMAND.COM with the arguments given causes it to reinvoke the batch file and vector to the section that turns echoing back on, generates a prompt with a blank line, then turns echoing back off, and exits (which causes the secondary command processor to terminate as well, which returns us to the line following the invocation of the command processor. As in the earlier example, we have to save and restore the original prompt string. The changes should be effective for as few commands as possible, so that if the program abends, the chances of having a corrupt prompt are low, though in reality, the only place where an abend is likely (from a user issued ^C) is when the changed prompt is being written to the file. However, during testing, with all echoing enabled, ^C would be active everywhere, and would also be quite likely to occur.

Variations on this theme give you the day name from $d and %3, the DOS version from $v and %5, the drive letter from $n and %3, or the drive and path with $p and %3.

I have seen a batch file that does all of this at once, putting the various elements into separate environment variables (the structure was completely different, and rather interesting, but not quite my style).


  ** Copyright 1995, Ted Davis - all rights reserved ** 

Input and feedback from readers are welcome. NOTE: the subject of the message must contain the word "batch" for the message to get past the spam filter.

Back to the Table of Contents page

Back to my personal links page - back to my home page