{"id":15,"date":"2007-07-16T02:32:00","date_gmt":"2007-07-16T07:32:00","guid":{"rendered":"synetech.ddns.net\/blogs\/smarticles\/blog\/2007\/07\/16\/software-os-command-prompt-null-character-and-other-control-codes-at-command-line\/"},"modified":"2011-03-03T18:12:54","modified_gmt":"2011-03-03T23:12:54","slug":"null-character-and-other-control-codes-at-command-line","status":"publish","type":"post","link":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/2007\/07\/16\/null-character-and-other-control-codes-at-command-line\/","title":{"rendered":"NULL Character (and other Control Codes) at Command Line"},"content":{"rendered":"<p>You can type control codes at command prompt in Windows (and DOS) by pressing the corresponding key with the Control key.  Get it, <strong>Control<\/strong> key for <strong>control<\/strong> code?<\/p>\n<p>The connection between letter and code is simple: add 0x40.  That is, for control code 1, add 0x40 to get 0x41 which is the ASCII code for \u2018A\u2019, therefore press Ctrl+A to get character 1 (SOH).<\/p>\n<p>But, the alphabet only accounts for 26 of the first 32 characters.  What about codes 27-31?  The correspondence remains the same.  Character 27 (ESC) is 0x1B+0x40=0x5B which is \u2018[\u2019, 28 (FS) is \u2018\\\u2019, 29 (GS) is \u2018]\u2019, 30 (RS) is \u2018^\u2019, and 31 (US) is \u2018_\u2019.<\/p>\n<p>Unfortunately, since \u2018_\u2019 is a shifted character, it requires holding Shift to create, so it is not possible to press Ctrl+Shift+- to get character 31 that way (and for the curious, no, Ctrl+- won\u2019t work).  For that, you\u2019ll have to resort to the classic Alt+Numpad method (Alt+31 on the numeric pad).<\/p>\n<p>Conversely, you cannot press Alt+0 to type character 0 (NUL).  To get null, you have to use the Control key.  Remember that it requires adding 0x40, so zero plus 40 is, well, 40.  That\u2019s right, 0x40 (64) is \u2018@\u2019 so, pressing Ctrl+Shift+2 (or just Ctrl+2) gets some sort of reaction.  However, it does not seem to produce the expected effect, probably because nulls are string terminators for any software that uses ASCIIZ encoding (a very common method).  (So Ctrl+2 is Null; that explains why it can sometimes be used as an abort chord similar to Ctrl+C or Break).<\/p>\n<p>In practice (in at least XP\u2019s command line), Ctrl+@ causes the prompt \u201cMore? \u201d, after which it passes whatever the user enters to the program as a parameter.  For example the command <code>echo ^@<\/code> followed by the the user entering <code>testing<\/code> would print out <code>testing<\/code> because the string was piped into the echo command.  Another example: <code>dir ^@<\/code> allows the user to select the file\/directory to list (entering <code>\/s<\/code> at the prompt would display all subdirectories).  There does not seem to be a way to prevent the prompt from being displayed (not even by redirecting to nul).<\/p>\n<p>No doubt, some creative and enterprising individual will be able to exploit this <em>feature<\/em> to enhance batch files.<\/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>You can type control codes at command prompt in Windows (and DOS) by pressing the corresponding key with the Control key. Get it, Control key for control code? The connection between letter and code is simple: add 0x40. That is, for control code 1, add 0x40 to get 0x41 which is the ASCII code for [&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-15","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\/15","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=15"}],"version-history":[{"count":0,"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"wp:attachment":[{"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/synetech.ddns.net\/blogs\/smarticles\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}