在环境变量Windows控制台宽度 [英] Windows console width in environment variable

查看:282
本文介绍了在环境变量Windows控制台宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能获得Windows控制台的当前宽度在一个批处理文件中的环境变量?

How can I get the current width of the windows console in an environment variable within a batch file?

推荐答案

我喜欢使用Windows内置的模式命令的办法。
请尝试以下批处理文件:

I like the approach using the built-in mode command in 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, and not the size of the window (which is scrollable).

如果你想在Windows控制台的高度,你可以替换 FINDSTR 前pression与。再次,它会返回缓冲区,而不是窗口的高度......我个人希望有一个大的缓冲区以允许通过滚动历史回来,所以对我行通常会报告3000:)

If you wanted the height of the windows console, you can replace Columns in the findstr expression with Lines. 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 :)

只是为了好玩,这里的 FINDSTR A版不使用过滤输出...的情况下,(由于某种原因)你有<$的厌恶C $ C> FINDSTR :

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 of 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 SP3,在许多不同的窗口(包括一名执行经理FAR)的。

Note, this was all tried in Windows XP SP3, in a number of different windows (including one executing FAR manager).

这篇关于在环境变量Windows控制台宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆