Computer Hope

Microsoft => Microsoft DOS => Topic started by: PiotrMP006 on April 02, 2019, 02:17:01 AM

Title: How to check console window width columns in bath script?
Post by: PiotrMP006 on April 02, 2019, 02:17:01 AM
Hi

How to check console window width columns in bath script?
Title: Re: How to check console window width columns in bath script?
Post by: Salmon Trout on April 02, 2019, 11:58:01 AM
Parse output of mode con command using FOR /F. Note: must escape pipe symbol | with caret ^.

@echo off
for /f "tokens=1-2" %%A in ('mode con ^| find "Columns"') do set colwide=%%B
echo This console is %colwide% columns wide.
pause


Output of batch:

C:\>colwidth.bat
This console is 104  columns wide.
Press any key to continue . . .


Complete output of mode con

C:\>mode con

Status for device CON:
----------------------
    Lines:          9001
    Columns:        104
    Keyboard rate:  31
    Keyboard delay: 1
    Code page:      850


Note: Height is height of buffer, not height of window.