You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Windows 11后CMD窗口大小设置的PowerShell异常问题

问题描述

我有一个用于设置命令窗口大小的批处理文件consize1.bat,内容如下:

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;}"

另有测试批处理文件testargs.bat调用它:

call consize1 125 70 125 9999

直接从命令行运行testargs.bat可正常工作,但使用start "test" testargs在新命令窗口启动时,出现如下错误:

Exception setting "buffersize": "Cannot set the buffer size because the size specified is too large or too small.
Parameter name: value
Actual value was 125,9999."
At line:1 char:75
+ ... rawui;$B=$W.buffersize;$B.width=125;$B.height=9999;$W.buffersize=$B;}
+                                                        ~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting

该操作在Windows 10中可正常执行。

解决方案

方法1:添加延迟等待窗口初始化

修改consize1.bat,在PowerShell命令前加入短暂延迟,确保新窗口完成初始化:

mode con: cols=%1 lines=%2
timeout /t 1 /nobreak >nul
powershell -command "&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=%3;$B.height=%4;$W.buffersize=$B;}"

方法2:调整start命令的调用逻辑

改用start直接启动带参数的CMD窗口,确保窗口就绪后再执行设置命令:

start "test" cmd /k "call consize1 125 70 125 9999"

方法3:切换到Windows Terminal

如果环境允许,使用Windows Terminal替代传统CMD窗口,它对缓冲区大小的限制更宽松,窗口初始化逻辑更稳定,原命令通常可直接正常运行。

原因分析

当前系统(推测为Windows 11)的CMD窗口初始化逻辑与Windows 10存在差异:

  • 用start启动新窗口时,窗口未完全完成初始化就执行缓冲区调整命令,此时系统判定9999的高度超出临时限制。
  • 直接运行时,当前窗口已处于稳定状态,系统接受更大的缓冲区高度设置。

内容的提问来源于stack exchange,提问作者Adrian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 01:37:47