́╗┐' is not recognized as an internal or external command

26

6

When executing certain files (mainly batch) using PsExec I get these weird ́╗┐' symbols before my command. My initial thought was, that I were using wrong encoding, but after checking, I realized that all my files were using UTF-8.

miestasmia

Posted 2013-05-29T14:42:32.013

Reputation: 481

Why not convert them to UTF-16LE instead? – Ignacio Vazquez-Abrams – 2013-05-29T14:54:36.003

What's the difference? – miestasmia – 2013-05-29T14:56:28.157

The difference is that Windows doesn't usually use UTF-8. – Ignacio Vazquez-Abrams – 2013-05-29T15:41:54.810

Answers

33

I get these weird ́╗┐' symbols before my command […] all my files were using UTF-8.

This has two causes:

  1. cmd.exe does not support UTF-8. It always uses one of the single-byte encodings often called "OEM" – cp437, cp775, and so on, depending on the system's regional settings.

    (I expected it to support UTF-16 as well, but apparently not; not even if I added the UTF-16 BOM.)

  2. Your text editor is adding an UTF-8 "byte order mark" (bytes EF BB BF) to the beginning of all UTF-8 files.

    When cmd.exe reads your script, it doesn't know what to do with the mark – it sees the BOM as three ordinary cp437 characters, , and attempts to use them as part of the command name.

Configure your editor to stop adding the BOM to UTF-8–encoded files. (It only makes sense in UTF-16, and is very useless in UTF-8.)

Would compiling the batch files into an exe solve the issue?

uh

what

user1686

Posted 2013-05-29T14:42:32.013

Reputation: 283 655

3I wouldn't say BOMs are "very useless" in UTF-8; though they are in this particular case. Many applications use them to determine the text actually is UTF-8 and not another encoding. – Dour High Arch – 2013-05-29T15:09:59.750

21

To further @dsolimano's answer, if you are specifically using Visual Studio, and in my case it's 2013, I fixed it by doing the following:

  1. Open Visual Studio.
  2. Click Tools > Options.
  3. Click Text Editor > File Extension.
  4. In the Extension box, enter bat.
  5. In the Editor drop down, select Source Code (Text) Editor With Encoding and click Add.
  6. Click OK to save and exit.

Now, when you open a .bat file from within Visual Studio, you will initially get prompted with:

enter image description here

You will want to drill down through the options until you come to the DOS option of your language:

enter image description here

Click OK to finish opening the file.


Ok, even though it should be fairly obvious at this point, if you can see the  characters at the beginning of your file, it would behoove you to remove them and save the file, now with the correct encoding. This is what prevents you from being prompted again next time.


With all of that in place, you will be glad to know that you may now view, edit, and save your .bat file(s) from within Visual Studio so that cmd.exe no longer gives you the aforementioned heinous error of:

'' is not recognized as an internal or external command, operable program or batch file.

Code Maverick

Posted 2013-05-29T14:42:32.013

Reputation: 453

3This fix works in VS2017 perfectly too – Greg Trevellick – 2018-06-19T20:25:59.327

3I never would have guessed this. Still a valid solution for VS2019. – hbulens – 2019-11-28T14:26:14.063

10

Those are Unicode Byte Order Marks. Cmd.exe doesn't understand them. If you resave your files in Notepad with ANSI encoding, that should fix the problem.

For example, I created this batch file:

echo Hello World

First I save it with UTF-8 encoding

C:\Users\DSolimano\Desktop\junk>test.bat

C:\Users\DSolimano\Desktop\junk>echo Hello World
'echo' is not recognized as an internal or external command,
operable program or batch file.

Then with Unicode

C:\Users\DSolimano\Desktop\junk>test.bat

C:\Users\DSolimano\Desktop\junk>■e
'■e' is not recognized as an internal or external command,
operable program or batch file.

And finally with ANSI

C:\Users\DSolimano\Desktop\junk>test.bat

C:\Users\DSolimano\Desktop\junk>echo Hello World
Hello World

dsolimano

Posted 2013-05-29T14:42:32.013

Reputation: 2 778

4

As explained earlier, this character is the unicode character BOM (Byte Order Mark) used as a signature and that cmd.exe does not recognize.

You can delete it safely in many ways.

I've found very easy to do as follows:

  1. open the file in Notepad++
  2. go to Encoding menu
  3. tick the option: Encode in UTF-8 without BOM
  4. Save, and that's it.

Sabri

Posted 2013-05-29T14:42:32.013

Reputation: 41