我知道你可以右键点击属性->布局并手动更改它。
但是,你如何从Windows批处理脚本中更改它呢?
我知道你可以使用类似于以下内容的脚本更改其大小:
MODE CON: COLS=90 LINES=10
但是,你如何更改缓冲区大小呢?
该脚本将运行一段时间,并有时在失败和退出之前需要一些时间,因此我需要更大的缓冲区。
我知道你可以右键点击属性->布局并手动更改它。
但是,你如何从Windows批处理脚本中更改它呢?
我知道你可以使用类似于以下内容的脚本更改其大小:
MODE CON: COLS=90 LINES=10
但是,你如何更改缓冲区大小呢?
该脚本将运行一段时间,并有时在失败和退出之前需要一些时间,因此我需要更大的缓冲区。
我刚刚在搜索这个确切问题的答案,结果发现这个命令本身会调整缓冲区!
mode con:cols=140 lines=70
lines=70 实际上调整的是“屏幕缓冲区大小”设置中的高度,而不是“窗口大小”设置中的高度。
可以通过使用“lines = 2500”(或您想要的任何缓冲区)的设置运行命令,然后检查窗口的“属性”,您将看到确实已将缓冲区设置为2500。
我的批处理脚本最终看起来像这样:
@echo off cmd "mode con:cols=140 lines=2500"
我在尝试使用mode con
命令设置Windows 7上的最大行数,并发现可以将其设置为32766,即2^15-2,并且您可以使用以下命令进行设置
mode con lines=32766
虽然你也可以从GUI中设置屏幕缓冲区大小,但最大值只能达到9999。
mode con:cols = 140 lines = 70
。从已接受的答案中得到的。 - FluorescentGreen5mode con lines=32766
该命令设置缓冲区,并将窗口高度增加至全屏,这样看起来很丑。
您可以直接在注册表中更改设置:
:: escape the environment variable in the key name
set mySysRoot=%%SystemRoot%%
:: 655294544 equals 9999 lines in the GUI
reg.exe add "HKCU\Console\%mySysRoot%_system32_cmd.exe" /v ScreenBufferSize /t REG_DWORD /d 655294544 /f
:: We also need to change the Window Height, 3276880 = 50 lines
reg.exe add "HKCU\Console\%mySysRoot%_system32_cmd.exe" /v WindowSize /t REG_DWORD /d 3276880 /f
Module ConsoleBuffer
Sub Main()
Console.WindowWidth = 100
Console.BufferWidth = 100
Console.BufferHeight = 1000
End Sub
End Module
我修改了代码,首先设置Console.WindowWidth
,然后再设置Console.BufferWidth
,因为如果你尝试将Console.BufferWidth
设置为小于当前Console.WindowWidth
的值,程序将抛出异常。
这只是一个示例...您应该添加处理命令行参数和错误处理的代码。
注意:它似乎会使脚本忘记变量(或者至少在我的脚本中是这样),因此建议仅在脚本的开头和/或结尾处调用该命令,或者在您不依赖于会话局部变量的其他位置调用。
regedit /s cmd_settings.reg
start /wait batch_script.bat
reg delete "HKEY_CURRENT_USER\Console\%%SystemRoot%%_system32_cmd.exe" /f
@echo off
echo test!
pause
exit
“DOS命令提示符”已经不存在了。DOS在Windows ME(7/11/2006)中完全消失。在Windows NT(即NT、2K、XP、Vista、7)中,它被简称为命令提示符。
没有内置的cmd.exe命令可以改变屏幕缓冲区。可以通过Console API Functions来改变它,所以您可能能够创建一个实用程序来修改它。我自己从未尝试过这种方法。
另一个建议是将输出重定向到文件和屏幕,以便您有一个“硬拷贝”。Windows没有像Unix那样的TEE命令,但有人已经解决了这个问题。
#include <iostream>
#include <windows.h>
using namespace std;
// SetWindow(Width,Height,WidthBuffer,HeightBuffer) -- set console size and buffer dimensions
//
void SetWindow(int Width, int Height, int WidthBuffer, int HeightBuffer) {
_COORD coord;
coord.X = WidthBuffer;
coord.Y = HeightBuffer;
_SMALL_RECT Rect;
Rect.Top = 0;
Rect.Left = 0;
Rect.Bottom = Height - 1;
Rect.Right = Width - 1;
HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE); // Get Handle
SetConsoleScreenBufferSize(Handle, coord); // Set Buffer Size
SetConsoleWindowInfo(Handle, TRUE, &Rect); // Set Window Size
} // SetWindow
// main(Width,Height,WidthBuffer,HeightBuffer) -- main
//
int main(int argc, char *argv[]) {
int width = 80;
int height = 25;
int wbuffer = width + 200;
int hbuffer = height + 1000;
if ( argc == 5 ){
width = atoi(argv[1]);
height = atoi(argv[2]);
wbuffer = atoi(argv[3]);
hbuffer = atoi(argv[4]);
} else if ( argc > 1 ) {
cout << "Usage: " << argv[0] << " [ width height bufferwidth bufferheight ]" << endl << endl;
cout << " Where" << endl;
cout << " width console width" << endl;
cout << " height console height" << endl;
cout << " bufferwidth scroll buffer width" << endl;
cout << " bufferheight scroll buffer height" << endl;
return 4;
}
SetWindow(width,height,wbuffer,hbuffer);
return 0;
}
我知道这个问题已经有9年了,但或许对某些人来说仍然很有兴趣。根据问题所述,如果只是想更改缓冲区大小,可以使用Powershell。最短的Powershell命令如下:
powershell -command "&{(get-host).ui.rawui.buffersize=@{width=155;height=999};}"
将宽度和高度的值替换为所需的值。
但是,你提出问题的原因可能是要修改命令行窗口的大小,而不会减少缓冲区的大小。为此,你可以使用以下命令:
start /b powershell -command "&{$w=(get-host).ui.rawui;$w.buffersize=@{width=177;height=999};$w.windowsize=@{width=155;height=55};}"
start /b
命令。PowerShell命令有时需要几秒钟才能执行。通过此额外命令,PowerShell可以并行运行,并不会显著延迟后续命令的处理。powershell.exe -command "& {$pshost = Get-Host;$pswindow = $pshost.UI.RawUI;$newsize = $pswindow.BufferSize;$newsize.height = 150;$pswindow.buffersize = $newsize;}"