0

I know I can enter the command

MODE CON

and get the number of lines in the Windows Command Prompt buffer, but I need a command that shows the number of lines being displayed. The usual value is 25, but I don't know of any command that actually reports the current value.

UPDATE: In response to Compo's comment, I did search for answers before posting my question. This question:

Way to find CMD window size from batch (*.bat) and maybe buffer size?

is the closest to what I was looking for, but none of the code samples produced the correct results for me (running Microsoft Windows 10 Enterprise 10.0.19044). More specifically, the command

for /f "tokens=3" %%A in ('reg query HKCU\Console /v WindowSize') do set /a window_height=%%A/65535

produced a value of 30 for an 80x25 window. This question:

How to change Screen buffer size in Windows Command Prompt from batch script

was one of several that described using MODE CON to change the size of the window. This question:

How can I permanently customize window size/buffer size of Command Prompt in Windows 7?

was one of several that described how to resize the Command Prompt window interactively. Is this sufficient evidence that I did my due diligence before posting?

UPDATE 2: In response to Jeb's comment, the code

@echo off

set "ROWS="
set "CHARACTERS="
REM Read CMD Window Size in Rows and Characters per Row.
for /F "tokens=3" %%A in ('reg query HKCU\Console /v WindowSize') do set /A ROWS=%%A/65535
for /F "tokens=3" %%A in ('reg query HKCU\Console /v WindowSize') do set /A "CHARACTERS=%%A&0xffff
REM Test it ...
echo Rows: %ROWS%
echo Characters: %CHARACTERS%

for /f "tokens=2" %%A in ('mode con ^| find "Lines"') do set "window_height=%%A"
for /f "tokens=2" %%A in ('mode con ^| find "Columns"') do set "window_width=%%A"
for /f "tokens=3" %%A in ('reg query HKCU\Console /v ScreenBufferSize') do set /a window_buffer=%%A/65535
echo Window is %window_width%x%window_height% with a buffer of %window_buffer%

for /f "tokens=3" %%A in ('reg query HKCU\Console /v WindowSize') do set /a window_height=%%A/65535
echo Window is %window_width%x%window_height% with a buffer of %window_buffer%

produces the output

Rows: 30
Characters: 120
Window is 80x300 with a buffer of 9001
Window is 80x30 with a buffer of 9001

when run within an 80x25 command prompt window. The number of columns is correct, but the number of rows is too large by 5.

Leslie
  • 618
  • 4
  • 14
  • 2
    You have shown us no indication of having performed any research prior to posting this question. Please [Edit] your question to explain which of the site questions and answers you found, (on this subject), how you adapted them, what happened when you ran them, and the debugging information when you did that. – Compo Nov 16 '22 at 23:29
  • `none of the code samples produced the correct results` Is there an error of +-1, is it always zero, your computer crashes? It could be good idea to post your expected results and what you get. – jeb Nov 17 '22 at 15:40

0 Answers0