{"id":105483,"date":"2021-07-26T07:00:00","date_gmt":"2021-07-26T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=105483"},"modified":"2021-07-24T09:20:33","modified_gmt":"2021-07-24T16:20:33","slug":"20210726-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20210726-00\/?p=105483","title":{"rendered":"Diagnosing why your batch file prints a garbage character, one character, and nothing more"},"content":{"rendered":"<p>You&#8217;ve written a batch file, and you try to execute it, but instead of running, it just prints some weird garbage character, then the first character of the batch file, and then that&#8217;s it.<\/p>\n<p>Here&#8217;s the batch file:<\/p>\n<pre>@echo off\r\necho Hello, world.\r\n<\/pre>\n<p>And here&#8217;s what happens when you run it:<\/p>\n<pre>C:\\&gt;\u25a0@\r\n'\u25a0@' is not recognized as an internal or external command,\r\noperable program or batch file.\r\nC:\\&gt;\r\n<\/pre>\n<p>What&#8217;s going on here?<\/p>\n<p>Put on your thinking cap.<\/p>\n<p>The file was saved in UTF-16LE format with a byte order mark. The leading garbage character was the byte order mark being interpreted in the ANSI code page.<\/p>\n<p>But wait, you say. The UTF-16LE byte order mark is two characters long: 0xFF and 0xFE. Why did only one garbage character print?<\/p>\n<p>Because character 0xFF is invisible.<\/p>\n<p>The next Unicode character in the batch file is the at-sign, which in UTF-16LE is encoded as a <tt>@<\/tt> followed by a null byte. The <tt>@<\/tt> is read from the batch file, but the null causes the command processor to think it reached the end of the file.<\/p>\n<p>That means that the batch file is treated as if it consisted of a single line. And that explains the error message.<\/p>\n<p>Save the batch file as ANSI rather than UTF16-LE, and that will fix it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Following the clues you have.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-105483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Following the clues you have.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/105483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=105483"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/105483\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=105483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=105483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=105483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}