10

I am trying to get a batch file to work. Whenever I attempt to run a .bat the command line returns '■m' is not recognized... error, where "m" is the first letter of the file. For example:

md c:\testsource md c:\testbackup

Returns

C:>"C:\Users\Michael\Dropbox\Documents\Research\Media\Method Guide\Program\test .bat"

C:>■m '■m' is not recognized as an internal or external command, operable program or batch file.

Things I have tried:

  1. Changing Path variables, rebooting, etc.
  2. Changing file directory (i.e. run from C:)
  3. Running example files from web (like above) to check for syntax errors.

Thanks

webelo
  • 1,251
  • 1
  • 11
  • 27

3 Answers3

18

What text editor are you writing this in? It seems like your text editor may save the file as UTF-16 encoded text, which cmd.exe can't handle. Try setting the "coding"/"file encoding" to "ANSI" when saving the file.

This results in the first byte being a byte-order-mark (telling other editors how to process the file), and cmd.exe can't deal with this.

Christian Aichinger
  • 6,691
  • 2
  • 37
  • 59
6

In addition to the approved answer I would add the case where is a PowerShell command the one that creates the file... PowerShell comes by default with the UTF-16 encoding.

To solve your problem then, force the file encoding lie this: | out-file foo.txt -encoding utf8

Answer based on this other answer.

juagicre
  • 1,007
  • 30
  • 39
  • 1
    thx! i ended up using `-encoding ascii` as even `-encoding utf8` left me with a bat file that would not execute. – WEBjuju Apr 19 '19 at 20:40
0

In windows 10 I had the same issue. Changing the character set to UTF-8 made it worse. It worked correctly when I selected Encoding as UTF-8-NO BOM.

Gogu CelMare
  • 567
  • 3
  • 14