指定执行批处理文件时命令提示符的大小 [英] Specify the size of command prompt when executing a batch file

查看:37
本文介绍了指定执行批处理文件时命令提示符的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何指定命令提示符的字体和窗口的大小?我正在使用 Windows 7 专业版.好的.对不起,我正在尝试使用命令来做上述事情,所以我不接受那些按属性"的答案.

How do I specify the font of command prompt and the size of the window? I'm using Windows 7 Professional. OK. I'm sorry, I'm trying to use a command to do the above things, so I'm not accepting those "press-the-properties" answer.

推荐答案

如果您想以编程方式更改控制台字体大小,请参阅 此页面此页面.您基本上必须将该模块源从 technet 页面复制粘贴到本地计算机上名为 SetConsoleFont.psm1 的新文件中.把它放到同名文件夹中,没有 ext(所以它变成了 SetConsoleFontSetConsoleFont.psm1).在命令行中,powershell -command "echo $env:PSModulePath" 以查看应该将 SetConsoleFont 文件夹放在哪里(可能在 %userprofile%DocumentsWindowsPowerShellModules).

If you want to change the console font size programmatically, see this page and this page. You basically have to copypaste that module source from the technet page into a new file called SetConsoleFont.psm1 on your local machine. Put it into a folder of the same name without ext (so it becomes SetConsoleFontSetConsoleFont.psm1). From the command line, powershell -command "echo $env:PSModulePath" to see where you should put that SetConsoleFont folder (probably in %userprofile%DocumentsWindowsPowerShellModules).

如果你想在你的批处理脚本中包含那个 technet 脚本并让你的批处理脚本在用户的机器上创建 [module_path_dir]SetConsoleFontSetConsoleFont.psm1,我建议使用 批处理脚本 heredoc 将是一种包含它并动态编写它的简单方法.

If you want to include that technet script within your batch script and have your batch script create [module_path_dir]SetConsoleFontSetConsoleFont.psm1 on the user's machine, I suggest a batch script heredoc would be an easy way to include it and write it dynamically.

使用模块路径中的模块,您现在可以从 cmd 行使用它.

With the module in your module path, you can now use it from the cmd line.

powershell -command "&{set-executionpolicy remotesigned; Import-Module SetConsoleFont; Get-ConsoleFontInfo | Format-Table -AutoSize}"

将向您显示控制台可用的字体大小表格.从 nFont 列中选择一个并像这样激活它:

will show you a table of the font sizes available to your console. Choose one from the nFont column and activate it like this:

powershell -command "&{set-executionpolicy remotesigned; Import-Module SetConsoleFont; Set-ConsoleFont 6}"

如果您只想调整控制台窗口和缓冲区的大小,那就简单多了.不需要模块或导入或执行策略覆盖.mode con: cols=n1 lines=n2 将更改窗口尺寸,并且有一个 PowerShell one-liner 用于更改缓冲区(回滚历史记录)大小.

If all you want to do is resize the console window and buffer, that's much simpler. No modules or importing or execution policy overriding is needed. mode con: cols=n1 lines=n2 will change the window dimensions, and there's a PowerShell one-liner for changing the buffer (scrollback history) size.

:: Resize the console window and increase the buffer to 10000 lines
call :consize 80 33 80 10000

:: put the main part of your bat script here.
:: script
:: script
:: script
:: etc.

goto :EOF

:consize <columns> <lines> <buffercolumns> <bufferlines>
:: change console window dimensions and buffer
mode con: cols=%1 lines=%2
powershell -command "&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=%3;$B.height=%4;$W.buffersize=$B;}"
goto :EOF

这篇关于指定执行批处理文件时命令提示符的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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