How to change Screen buffer size in Windows Command Prompt from batch script

后端 未结 14 1517
清歌不尽
清歌不尽 2020-12-02 09:59

I know you can do right click properties ->layout and there change it manually.

But how would you go about changing it from a Windows batch script?

I know yo

14条回答
  •  温柔的废话
    2020-12-02 10:36

    I know the question is 9 years old, but maybe for someone it will be interested furthermore. According to the question, to change the buffer size only, it can be used Powershell. The shortest command with Powershell is:

    powershell -command "&{(get-host).ui.rawui.buffersize=@{width=155;height=999};}"
    

    Replace the values of width and height with your wanted values.

    But supposedly the reason of your question is to modify the size of command line window without reducing of the buffer size. For that you can use the following command:

    start /b powershell -command "&{$w=(get-host).ui.rawui;$w.buffersize=@{width=177;height=999};$w.windowsize=@{width=155;height=55};}"
    

    There you can modify the size of buffer and window independly. To avoid an error message, consider that the values of buffersize must be bigger or equal to the values of windowsize.

    Additional implemented is the start /b command. The Powershell command sometimes takes a few seconds to execute. With this additional command, Powershell runs parallel and does not significantly delay the processing of the following commands.

提交回复
热议问题