Discussion:
Get screen width (in characters) in batch file?
(too old to reply)
Kenny McCormack
2020-11-19 00:48:56 UTC
Permalink
In a batch file, I want to get the width of the screen (e.g., 80, in the
normal case) into a variable. This is, e.g., the number displayed in the
"Properties" of the Command Prompt window - as the "screen width".

I know how to get this is in a regular programming language (e.g., C or
C++), using a Win32 API call, but I don't know of any easy way to get it
purely in batch (CMD.EXE).

Also, not interested in any solutions that involve things like PowerShell
or VBA. As I said, if it requires going to a regular programming language,
I already know how to do that.

Any ideas?
--
"The party of Lincoln has become the party of John Wilkes Booth."

- Carlos Alazraqui -
Zaidy036
2020-11-19 01:03:14 UTC
Permalink
Post by Kenny McCormack
In a batch file, I want to get the width of the screen (e.g., 80, in the
normal case) into a variable. This is, e.g., the number displayed in the
"Properties" of the Command Prompt window - as the "screen width".
I know how to get this is in a regular programming language (e.g., C or
C++), using a Win32 API call, but I don't know of any easy way to get it
purely in batch (CMD.EXE).
Also, not interested in any solutions that involve things like PowerShell
or VBA. As I said, if it requires going to a regular programming language,
I already know how to do that.
Any ideas?
MODE CON: COLS=xx LINES=yy
Kenny McCormack
2020-11-19 01:58:25 UTC
Permalink
Post by Zaidy036
Post by Kenny McCormack
In a batch file, I want to get the width of the screen (e.g., 80, in the
normal case) into a variable. This is, e.g., the number displayed in the
"Properties" of the Command Prompt window - as the "screen width".
I know how to get this is in a regular programming language (e.g., C or
C++), using a Win32 API call, but I don't know of any easy way to get it
purely in batch (CMD.EXE).
Also, not interested in any solutions that involve things like PowerShell
or VBA. As I said, if it requires going to a regular programming language,
I already know how to do that.
Any ideas?
MODE CON: COLS=xx LINES=yy
I think you misread the word "get" as "set".
--
Conservatives want smaller government for the same reason criminals want fewer cops.
Kerr-Mudd,John
2020-11-19 12:29:59 UTC
Permalink
Post by Kenny McCormack
Post by Zaidy036
Post by Kenny McCormack
In a batch file, I want to get the width of the screen (e.g., 80, in
the normal case) into a variable. This is, e.g., the number
displayed in the "Properties" of the Command Prompt window - as the
"screen width".
I know how to get this is in a regular programming language (e.g., C
or C++), using a Win32 API call, but I don't know of any easy way to
get it purely in batch (CMD.EXE).
Also, not interested in any solutions that involve things like
PowerShell or VBA. As I said, if it requires going to a regular
programming language, I already know how to do that.
Any ideas?
MODE CON: COLS=xx LINES=yy
I think you misread the word "get" as "set".
Well, the clue is there; parse the output of "mode con:" for "Columns:"
--
Bah, and indeed, Humbug.
Kenny McCormack
2020-11-19 19:03:28 UTC
Permalink
In article <***@144.76.35.198>,
Kerr-Mudd,John <***@127.0.0.1> wrote:
...
Post by Kerr-Mudd,John
Post by Kenny McCormack
Post by Zaidy036
MODE CON: COLS=xx LINES=yy
I think you misread the word "get" as "set".
Well, the clue is there; parse the output of "mode con:" for "Columns:"
Indeed. Thanks.

"mode con" delivers the goods.
--
People who want to share their religious views with you
almost never want you to share yours with them. -- Dave Barry
Zaidy036
2020-11-19 15:39:01 UTC
Permalink
Post by Kenny McCormack
Post by Zaidy036
Post by Kenny McCormack
In a batch file, I want to get the width of the screen (e.g., 80, in the
normal case) into a variable. This is, e.g., the number displayed in the
"Properties" of the Command Prompt window - as the "screen width".
I know how to get this is in a regular programming language (e.g., C or
C++), using a Win32 API call, but I don't know of any easy way to get it
purely in batch (CMD.EXE).
Also, not interested in any solutions that involve things like PowerShell
or VBA. As I said, if it requires going to a regular programming language,
I already know how to do that.
Any ideas?
MODE CON: COLS=xx LINES=yy
I think you misread the word "get" as "set".
MODE > [file]
FIND "Columns" [file] > [file 2]
SET /P _Col=<[file 2]
SET _Col=%_Col:Columns: =%
etc
Herbert Kleebauer
2020-11-19 20:39:45 UTC
Permalink
Post by Zaidy036
MODE > [file]
FIND "Columns" [file] > [file 2]
SET /P _Col=<[file 2]
SET _Col=%_Col:Columns: =%
etc
@echo off
for /f "tokens=2" %%i in ('mode con:^|find "Columns"') do set /a n=%%i
echo %n%
Kerr-Mudd,John
2020-11-19 16:43:13 UTC
Permalink
Post by Kenny McCormack
In a batch file, I want to get the width of the screen (e.g., 80, in
the normal case) into a variable. This is, e.g., the number
displayed in the "Properties" of the Command Prompt window - as the
"screen width".
I know how to get this is in a regular programming language (e.g., C
or C++), using a Win32 API call, but I don't know of any easy way to
get it purely in batch (CMD.EXE).
Also, not interested in any solutions that involve things like
PowerShell or VBA. As I said, if it requires going to a regular
programming language, I already know how to do that.
Any ideas?
Sure. What's my fee?
--
Bah, and indeed, Humbug.
Kerr-Mudd,John
2020-11-19 22:06:50 UTC
Permalink
Post by Kerr-Mudd,John
Post by Kenny McCormack
In a batch file, I want to get the width of the screen (e.g., 80, in
the normal case) into a variable. This is, e.g., the number
displayed in the "Properties" of the Command Prompt window - as the
"screen width".
I know how to get this is in a regular programming language (e.g., C
or C++), using a Win32 API call, but I don't know of any easy way to
get it purely in batch (CMD.EXE).
Also, not interested in any solutions that involve things like
PowerShell or VBA. As I said, if it requires going to a regular
programming language, I already know how to do that.
Any ideas?
Sure. What's my fee?
Sorry, I was a bit grumpy earlier;

@echo off
rem mode con: cols=97
for /F "tokens=1,2 delims= " %%i in ('mode con:') do if %%i==Columns:
echo cols=%%j
--
Bah, and indeed, Humbug.
Kerr-Mudd,John
2020-11-20 12:41:53 UTC
Permalink
On Thu, 19 Nov 2020 16:43:13 GMT, "Kerr-Mudd,John"
On Thu, 19 Nov 2020 00:48:56 GMT,
Post by Kenny McCormack
In a batch file, I want to get the width of the screen
(e.g., 80, in
Post by Kenny McCormack
the normal case) into a variable. This is, e.g., the
number
Post by Kenny McCormack
displayed in the "Properties" of the Command Prompt window
- as the
Post by Kenny McCormack
"screen width".
I know how to get this is in a regular programming
language (e.g., C
Post by Kenny McCormack
or C++), using a Win32 API call, but I don't know of any
easy way to
Post by Kenny McCormack
get it purely in batch (CMD.EXE).
Also, not interested in any solutions that involve things
like
Post by Kenny McCormack
PowerShell or VBA. As I said, if it requires going to a
regular
Post by Kenny McCormack
programming language, I already know how to do that.
Any ideas?
Sure. What's my fee?
Sorry, I was a bit grumpy earlier;
@echo off
rem mode con: cols=97
for /F "tokens=1,2 delims= " %%i in ('mode con:') do if %%
echo cols=%%j
I'm also a bit rusty; no need for the 'delims= '

for /F "tokens=1,2" %i in ('mode con:') do if %i == Columns:
set cols=%j
--
Bah, and indeed, Humbug.
mokomoji
2021-01-25 10:00:37 UTC
Permalink
Post by Kenny McCormack
In a batch file, I want to get the width of the screen (e.g., 80, in the
normal case) into a variable. This is, e.g., the number displayed in the
"Properties" of the Command Prompt window - as the "screen width".
I know how to get this is in a regular programming language (e.g., C or
C++), using a Win32 API call, but I don't know of any easy way to get it
purely in batch (CMD.EXE).
Also, not interested in any solutions that involve things like PowerShell
or VBA. As I said, if it requires going to a regular programming language,
I already know how to do that.
Any ideas?
--
"The party of Lincoln has become the party of John Wilkes Booth."
- Carlos Alazraqui -
@echo off
setlocal
cd /d "%~dp0"
chcp 437
cls
for /f "tokens=1* delims=: " %%f in ('mode con') do (
call set /a z_num+=1
call set "z_mode_%%z_num%%=%%~g"
)
echo lines=%z_mode_3%
echo colums=%z_mode_4%
:end
endlocal
pause

Loading...