I discovered a method to correctly get the number of displayed lines in the cmd.exe window. Here it is:
Code: Select all
@if (@CodeSection == @Batch) @then
@echo off
setlocal
rem Get the number of *displayed* lines in the cmd.exe window
rem Antonio Perez Ayala
for /F "tokens=2 delims=:" %%a in ('mode con') do set /A "min=lastLines=0, max=%%a" & goto nextLine
:nextLine
set /A "lines=(min+max)/2"
cscript //nologo //E:JScript "%~F0" Q
(for /L %%i in (1,1,%lines%) do @echo/) | more /E /C
cscript //nologo //E:JScript "%~F0" q
set /P "test="
if %test% equ Q (
set /A "min=lines+1"
set /P "="
) else (
set /a "max=lines-1"
)
if %lines% neq %lastLines% set "lastLines=%lines%" & goto nextLine
set /A lines+=2
cls
echo Lines=%lines%
goto :EOF
@end
// JScript section
WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0)+"{ENTER}");
This method may also be used to know the maximum number of lines that can be displayed on the screen. To do that, just set the buffer size to a high number with MODE command and then get the number of window lines. Tested on Windows 8.1
About the method used, as jeb would say: "is obvious"
Antonio