Weird characters (´╗┐) at the start of a batch file

31

3

I am working with batch files in Windows, using both Notepad, and Notepad++. When I run the batch files, which all start with @echo off, I see the first line (when running on two separate machines) reading ´╗┐@echo off, and then all the REM lines below it appear as well.

I have tried changing the encoding in Notepad++, but it claims they are already at UTF-8 encoding, which appears to be correct.

What do I need to do to get these files to run properly?

Canadian Luke

Posted 2014-06-16T21:09:34.927

Reputation: 22 162

Question was closed 2017-03-25T10:37:50.123

@luu my question is about notepad++ specifically – Canadian Luke – 2017-03-25T04:24:55.180

Note that regular Notepad, when saving with UTF8, does not allow to save without BOM, and will add those characters. – dmcontador – 2019-09-20T06:11:14.067

Answers

10

Turns out it needs to be set to ANSI encoding to work properly. To set this, I chose Encoding->Encode in ANSI.

To figure this out, I tried to create a batch file from the command line.

echo @echo off > batch.bat
echo REM Some comment... >> batch.bat
echo echo Hello world! >> batch.bat

I then opened this file up in Notepad++, and checked the encoding in the lower right corner, which read ANSI as UTF-8. I don't know why it adds that last bit, but it seems to work now.

Canadian Luke

Posted 2014-06-16T21:09:34.927

Reputation: 22 162

ANSI is not really an encoding. Presumably it refers to your Windows system's default code page. That will vary from one system to another, depending on configuration.

– Cody Gray – 2014-06-17T08:11:24.313

This is not correct. The BOM is a character set encoding artifact. – Thorbjørn Ravn Andersen – 2014-06-17T08:20:31.733

@ThorbjørnRavnAndersen Who's incorrect, me or Cody? – Canadian Luke – 2014-06-17T15:08:41.330

27

It looks like the DOS ASCII encoding of the Byte Order Mark for UTF-8 (0xEF 0xBB 0xBF): http://en.wikipedia.org/wiki/Byte_order_mark

In Notepad++ try encoding it as "UTF-8 Without BOM" or as plain ASCII. I think the use of BOM for UTF-8 is discouraged for this reason, it's not exactly backwards compatible with ASCII.

baochan

Posted 2014-06-16T21:09:34.927

Reputation: 1 019

1I ran into this when using Visual Studio to create a new text file. – Sam Goldberg – 2017-03-07T18:55:41.860

2Absolutely right, except the 'DOS ASCII' is DOS code page 850, as shown by experimention in Python: >>> print u'\ufeff'.encode('utf8').decode('cp850') ´╗┐ – deltab – 2014-06-17T06:00:59.267

@deltab Ah, good find. I wasn't sure what the encoding was specifically called, just that I hadn't seen the line-art characters ╗┐ since the days of MS-DOS 5/Windows 3.11. Modern Windows must run batch files with that encoding for compatibility? – baochan – 2014-06-17T13:34:37.460