{"id":14,"date":"2007-07-16T03:31:00","date_gmt":"2007-07-16T08:31:00","guid":{"rendered":"synetech.ddns.net\/blogs\/smarticles\/blog\/2007\/07\/16\/software-os-command-prompt-cls-is-a-hack\/"},"modified":"2011-03-03T18:13:02","modified_gmt":"2011-03-03T23:13:02","slug":"cls-is-a-hack","status":"publish","type":"post","link":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/2007\/07\/16\/cls-is-a-hack\/","title":{"rendered":"CLS is a Hack"},"content":{"rendered":"<p>Open a command prompt and type the following command: <code>cls&gt;clstest.txt<\/code>.  Now examine the contents of clstest.txt.  You will see that it contains one character: 0x0C\u2014FF which stands for form-feed.  That\u2019s right, CLS clears the screen by merely scrolling the previous contents out of sight by printing out a form-feed character; well, almost merely.<\/p>\n<p>If you are using XP or higher, set the command prompt window to have a larger buffer and try this command: <code>more \/p clstest.txt<\/code>.  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 by the number of lines equal to the console window\u2019s screen height, which can be less than the buffer height, effectively clearing the screen, but leaving <code>buffer.height-screen.height<\/code> lines unaffected; you can still scroll up to see the previous contents.  Using the CLS command however does erase the contents of the buffer and resets the cursor to the top-left most position.<\/p>\n<p>CLS prints a form-feed character because when it was first created back in the days of early versions of <acronym title=\"(Microsoft) Disk Operating System\">(MS-)DOS<\/acronym> there were no back-buffers and screens were a fixed size.<\/p>\n<p>This behavior of CLS is still present even in Windows 7. It is interesting to see some of the indelible backwards compatibilities.<\/p>\n<div class=\"tagcloud\"><a href=\"https:\/\/synetech.ddns.net\/blogs\/smarticles\/tag\/command-prompt\/\" rel=\"tag\">Command Prompt<\/a>, <a href=\"https:\/\/synetech.ddns.net\/blogs\/smarticles\/tag\/computers\/\" rel=\"tag\">Computers<\/a>, <a href=\"https:\/\/synetech.ddns.net\/blogs\/smarticles\/tag\/internals\/\" rel=\"tag\">Internals<\/a>, <a href=\"https:\/\/synetech.ddns.net\/blogs\/smarticles\/tag\/operating-systems\/\" rel=\"tag\">Operating Systems<\/a><\/div>","protected":false},"excerpt":{"rendered":"<p>Open a command prompt and type the following command: cls&gt;clstest.txt. Now examine the contents of clstest.txt. You will see that it contains one character: 0x0C\u2014FF which stands for form-feed. That\u2019s 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[33,14,37,9],"class_list":["post-14","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-command-prompt","tag-computers","tag-internals","tag-operating-systems"],"_links":{"self":[{"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/comments?post=14"}],"version-history":[{"count":0,"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/posts\/14\/revisions"}],"wp:attachment":[{"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/media?parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/categories?post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/tags?post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}