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 buffer size, and the window will adjust to match or max out at the screen size.
I would like to use mode 100,50
for the window size, but I also want to keep a arger buffer - for development at least I want mode 100,9999
.
Is there any way to do this?
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:
To get your desired size, you would simply use
I have written a tiny application for Windows that allows to "maximize" the window and buffer. It could be easily extended to allow passing parameters with custom values.
I have found a way to resize the buffer size without influencing the window size. It works thanks to a flaw in how batch works but it gets the job done.
How does it work? There is a syntax error in this command, it should be "mode 648, 78". Because of how batch works, the buffer size will first be resized to 648 and then the window resize will come but it will never finish, because of the syntax error. Voila, buffer size is adjusted and the window size stays the same. This produces an ugly error so to get rid of it just add the ">nul 2>nul" and you're done.
here another variant:
There's a 'ConSetBuffer' binary available that does specifically this, and I've found it to work reliably. It and related console utilities are available at the 'conutils.zip' link on this page.