设置CMD窗口大小:升级到Windows 11后的Powershell问题

huangapple go评论126阅读模式
英文:

Setting size of CMD windows: Powershell issue after upgrade to Windows 11

问题

我有一个批处理文件,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

我会收到这个错误:

设置"buffersize"时出现异常:"无法设置缓冲区大小,因为指定的大小过大或过小。
参数名称:值
实际值为125,9999。"
在行:1 字符:75
+ ... rawui;$B=$W.buffersize;$B.width=125;$B.height=9999;$W.buffersize=$B;}
+                                                        ~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting

这在Windows 10中可以正常工作。

英文:

I have a batch file, consize1.bat, to set command window sizes:

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

and a test batch file, testargs.bat, which calls it:

call consize1 125 70 125 9999

If I run testargs.bat directly from the command line, it works fine. However if I run it in a new command window using:

start "test" testargs

I get this error:

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

This all works fine in Windows 10.

答案1

得分: 1

指定的缓冲区大小(125,9999)在PowerShell命令中被解释为单个值而不是分开的宽度高度值。
要解决这个问题,您需要修改将参数传递给testargs.bat文件的方式。不要将它们作为单个字符串传递,而应该分别传递每个参数。这是testargs.bat文件的更新版本:

@echo off
call consize1 %1 %2 %3 %4

在调用testargs.bat时,逐个提供参数

start "test" testargs 125 70 125 9999

请注意,您的原始文本中包含一些特殊字符,已经被保留。

英文:

The buffer size specified (125,9999) in the PowerShell command is being interpreted as a single value instead of separate width and height values.
To resolve this issue, you need to modify the way you pass the arguments to the testargs.bat file. Instead of passing them as a single string, you should pass each argument separately. Here's an updated version of the testargs.bat file:

@echo off
call consize1 %1 %2 %3 %4

And when calling testargs.bat, provide the arguments individually:

start "test" testargs 125 70 125 9999

huangapple
  • 本文由 发表于 2023年7月17日 20:55:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76704687.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定