Purpose:Display a block of text in a batch file












TEXT can only be used in batch files. Both TEXT and ENDTEXT must be entered as the only commands on their respective lines, and cannot be included in a command group.


The TEXT command is useful for displaying menus, tables, special characters, or multiline messages. TEXT will display all lines in the batch file between itself and the terminating ENDTEXT. The display starts at the current display position, which allows you to start its display with other text, e.g., from the ECHOS command.


The lines between TEXT and ENDTEXT are not parsed. As a consequence, no environment variable expansion or other processing is performed, and all lines are displayed exactly as they are stored in the batch file, subject only to the choice of font and codepage differences, if any, between the program which created the file and that in effect during its execution. This makes it easy to include special characters, e.g., < | > in the text. However, if the ANSI X3.64 interpretation option is enabled, you can change screen colors by inserting ANSI X3.64 escape sequences anywhere in the text block. The ENDTEXT command itself will not be displayed.


You can also use the CLS or the COLOR command to set the default screen colors before executing TEXT.


Redirecting TEXT output


To redirect or pipe the entire block of text, use redirection or piping on the TEXT command itself as shown in the examples below. As with any other command, this redirection is not affected by redirection of all output of the batch file by the command which started the batch file. Attempting to redirect or pipe the actual text lines is ignored. Attempting to redirect or pipe the ENDTEXT line is invalid.


Warning: If the TEXT command is redirected or piped. and the redirection/piping fails, the lines of the batch file following the TEXT command are executed as if they were commands, causing potential harm. The simplest way to avoid trouble this may cause is to use the ON ERROR command before TEXT. See the second example below.




The following batch file fragment displays a simple menu:


@echo off & cls

screen 2 0


Enter one of the following:

 1 - Spreadsheet

 2 - Word Processing

 3 - Utilities

 4 - Exit


inkey /k"1234" Enter your selection:  %%key


The example below uses TEXT to display or append to a file (specified as the optional parameter of the batch file):


@echo off


setdos /x-6

set dest=%@if[%# GT 0,>> %1,]

setdos /x+6

set repeat=0

on error (unset dest & goto PROBLEM)


iff %repeat GT 1 then

 echo Repeated problems - quitting



set repeat=%@inc[%repeat]

text %dest


| Logical Drives |



subst %dest

echo. %dest

if %_transient eq 1 .and. %# EQ 0 pause