How can I get the current width of the windows console in an environment variable within a batch file?
相关问题
- Inheritance impossible in Windows Runtime Componen
- how to get running process information in java?
- Is TWebBrowser dependant on IE version?
- How can I have a python script safely exit itself?
- I want to trace logs using a Macro multi parameter
相关文章
- 在vscode如何用code runner打开独立的控制台窗口,以及设置好调试模式时窗口的编码?
- 如何让cmd.exe 执行 UNICODE 文本格式的批处理?
- 怎么把Windows开机按钮通过修改注册表指向我自己的程序
- Warning : HTML 1300 Navigation occured?
- Bundling the Windows Mono runtime with an applicat
- Windows 8.1 How to fix this obsolete code?
- Compile and build with single command line Java (L
- CosmosDB emulator can't start since port is al
try this (language/locale/.net independent):
tested on Windows XP and Windows 7, both in Czech language
You can't get it in an environment variable, but it is stored in the registry so you can access it from your batch script.
There are answers here about how to change it: How to change Screen buffer size in Windows Command Prompt from batch script
In a similar way you can use
reg.exe QUERY [key details]
rather thanreg.exe ADD [details]
. See the Technet documentation forHKCU\Console
for details.I like the approach using the built-in
mode
command in Windows. Try the following batch-file:Note that this will return the size of the console buffer, and not the size of the window (which is scrollable).
If you wanted the height of the windows console, you can replace
Columns
in thefindstr
expression withLines
. Again, it will return the height of the buffer, not the window... I personally like to have a big buffer to allow scrolling back through history, so for me the Lines usually reports about 3000 :)Just for fun, here's a version that doesn't use
findstr
to filter the output... in case (for some reason) you have a dislike offindstr
:Note, this was all tried in Windows XP SP3, in a number of different windows (including one executing FAR manager).
Powershell's
(Get-Host).UI.RawUI.WindowSize
property sets or returns the dimensions of the current console window. You can capture it with afor
loop thusly:Alright, here's one that doesn't require powershell to be installed. It composes, runs and deletes a .Net application to set a batch script variable. :)