Monday, July 16, 2007

[Software :: OS :: Command Prompt] CLS is a Hack

Open a command prompt and type the following command: cls>clstest.txt. Now examine the contents of clstest.txt. You will see that it contains one character: 0x12—FF which stands for form-feed. That’s right, CLS clears the screen by merely scrolling the previous contents out of sight by printing out a form-feed character; well, almost merely.

If you are using XP, set the command prompt window to have a larger buffer and try this command: more /p clstest.txt. It displays the contents of the file, expanding any form-feed characters it finds. What happens is that the display scrolls the previous contents up, effectively clearing the screen, but does not clear the buffer; you can still scroll up to see the previous contents. Using the CLS command however does erase the contents of the buffer.

CLS prints a form-feed character because when it was first created back in the days of (MS-)DOS there were no back-buffers and screens were a fixed size.

It is interesting to see some of the indelible backwards compatibilities.

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?