(view source code of screen.bat as plain text)
:: This batch file for NT shows 3 different ways to display text
:: plus a way to overcome the problem that CLS is ignored when
:: a batch file's output is redirected.
:: Written by Rob van der Woude
:: Since a simple CLS won't clear the screen when redirected,
:: we need to use MODE to clear the screen instead.
:: The FOR command is used to make sure we do not change the
:: console settings when using MODE CON.
FOR /F "TOKENS=2* DELIMS= " %%A IN ('MODE CON ^| FIND "Lines:"') DO SET LINES=%%A
MODE CON LINES=%LINES%
:: >CON writes directly to screen, blocking further redirection
ECHO Different ways to display text on screen>CON
ECHO CON Try to get rid of this message:>CON
ECHO neither ^>NUL nor ^>NUL 2^>^&1 will work>CON
:: 1>&2 redirects output to standard error, enabling further
:: redirection with 2>NUL
ECHO STDERR Standard error can be suppressed with 2^>NUL, 1>&2
ECHO but not with ^>NUL 1>&2
:: Standard output can be redirected using >NUL or 1>NUL
ECHO STDOUT Standard output can be suppressed with ^>NUL,
ECHO but not with 2^>NUL
page last modified: 2023-03-10