如何获取cmd窗口的高度(以行为单位)? [英] How to get the cmd window's height (in lines)?

查看:133
本文介绍了如何获取cmd窗口的高度(以行为单位)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行个性化的更多"命令,其中逐行输出行. 因此,我需要以线单位获取变量中窗口的高度. 有没有一种方法可以简单地在批处理文件中做到这一点?

I want to do a personalized "more" command where the lines are output page by page. Therefore, I need to get the height of the windows in a variable, in an unit of lines. Is there a way to do that simply in a batch file?

否则,我该如何使用more命令(或类似的命令),但要在每个页面上显示一个标题栏,以显示相应的标题栏?

Else, how could I use the more command (or a similar one), but with a header to see a kind of title bar at each page echoed?

推荐答案

由于您使用PowerShell标记了问题,因此将使用以下PowerShell脚本来获取PowerShell控制台高度:

Since you tagged your question with PowerShell, this is the PowerShell script you would use to get the PowerShell console height in lines:

C:\PS> $host.UI.RawUI.WindowSize.Height
50

要将其保存到BAT文件中的变量中,请执行以下操作:

To save that to a variable in a BAT file do this:

FOR /F "delims=" %A in ('powershell.exe -noprofile -command $host.ui.rawui.WindowSize.Height') do SET result=%A
echo %result%

这篇关于如何获取cmd窗口的高度(以行为单位)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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