I like the approach using the built-in command modeon Windows. Try the following batch file:
@echo off
for /F "usebackq tokens=2* delims=: " %%W in (`mode con ^| findstr Columns`) do set CONSOLE_WIDTH=%%W
echo Console is %CONSOLE_WIDTH% characters wide
Note that this will return the size of the console buffer, not the window size (which scrolls).
Windows, Columns findstr Lines. , , ... , , 3000:)
, , findstr ... ( - ) findstr:
@echo off
for /F "usebackq tokens=1,2* delims=: " %%V in (`mode con`) do (
if .%%V==.Columns (
set CONSOLE_WIDTH=%%W
goto done
)
)
:done
echo Console is %CONSOLE_WIDTH% characters wide
. Windows XP 3 (SP3) ( FAR).