Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for screen.bat

(view source code of screen.bat as plain text)

  1. @ECHO OFF
  2. :: This batch file for NT shows 3 different ways to display text
  3. :: plus a way to overcome the problem that CLS is ignored when
  4. :: a batch file's output is redirected.
  5. :: Written by Rob van der Woude
  6.  
  7. :: Since a simple CLS won't clear the screen when redirected,
  8. :: we need to use MODE to clear the screen instead.
  9. :: The FOR command is used to make sure we do not change the
  10. :: console settings when using MODE CON.
  11. FOR /F "TOKENS=2* DELIMS= " %%A IN ('MODE CON ^| FIND "Lines:"') DO SET LINES=%%A
  12. MODE CON LINES=%LINES%
  13.  
  14. :: >CON writes directly to screen, blocking further redirection
  15. ECHO.>CON
  16. ECHO.>CON
  17. ECHO            Different ways to display text on screen>CON
  18. ECHO.>CON
  19. ECHO CON        Try to get rid of this message:>CON
  20. ECHO            neither ^>NUL nor ^>NUL 2^>^&1 will work>CON
  21. ECHO.>CON
  22.  
  23. :: 1>&2 redirects output to standard error, enabling further
  24. :: redirection with 2>NUL
  25. ECHO STDERR     Standard error can be suppressed with 2^>NUL, 1>&2
  26. ECHO            but not with ^>NUL 1>&2
  27. ECHO. 1>&2
  28.  
  29. :: Standard output can be redirected using >NUL or 1>NUL
  30. ECHO STDOUT     Standard output can be suppressed with ^>NUL,
  31. ECHO            but not with 2^>NUL
  32.  

page last modified: 2024-02-26; loaded in 0.0176 seconds