Friday, April 13, 2018

Bat file returns error but works correctly


I have the following .bat file which used to work without any error but for some reason it's started to return an error every time I run it.


Here's the .bat file:


C:
start "" "C:\Program Files (x86)\NetBeans 7.0.1\bin\netbeans.exe"
D:
start "" "D:\standalone\My AutoHotkey Script.ahk"

The error:


enter image description here


Answer



You wrote your command script in UTF-8. Those three characters are the UTF-8 encoding of the Unicode Byte Order Mark, U+FEFF, displayed in code page 437. Scripts for Microsoft's command processor are always treated by the command processor as if encoded the current "OEM" code page (clearly 437 in your case), and should be written as such.


The reason that everything looked alright in Notepad is that Notepad recognizes BOMs and decodes the file accordingly. What Notepad was showing you was not what the command processor actually sees in the file.


Note that Notepad has no ability to read/write files in OEM code pages. If you are using characters in command scripts that are outwith the ASCII subset common to "OEM" and "Windows" code pages (fortunately, not the case here), then you cannot use Notepad for editing those scripts (unless you are capable of translating from "OEM" to "Windows" code pages in your head as you type).


Even then, you'll have trouble when Notepad silently prepends byte-order marks to your files when you accidentally save as UTF-8 instead of in the current Windows code page (which Notepad mis-names "ANSI"). That's almost certainly what happened here, in fact.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...