CMD: Set buffer height independently of window height

前端 未结 6 497
情话喂你
情话喂你 2020-12-05 06:17

I\'ve recently learned that I can control the size of the CMD window running my program with mode x,y. However I just as recently noticed that this sets the

6条回答
  •  星月不相逢
    2020-12-05 06:35

    I don't think there is a native batch command that gives independent control of buffer and window sizes. .NET can control both, but I don't think VBScript or JScript can access that functionality. But powershell can :-) See How Can I Expand the Width of the Windows PowerShell Console?

    Thankfully, the new settings are preserved in the CMD window when PowerShell exits.

    It is important that the window size is always less than or equal to the buffer size. To simplify things, I first use MODE to set both the window and buffer to the desired window size, and then I use powershell to set the buffer size.

    Here is a simple conSize.bat hybrid batch/powershell script that takes the sizes as parameters:

    @echo off
    :conSize  winWidth  winHeight  bufWidth  bufHeight
    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;}"
    

    To get your desired size, you would simply use

    call conSize 100 50 100 9999
    

提交回复
热议问题