A weird encoding problem in comments of Batch scripts

103 views Asked by At

I added an announcement of AGPL-3.0 licence in the header of my Batch script (saved in UTF-8). In addition, for the convenience of Chinese developers, I also added a Chinese translation link below it, like this:

chcp 65001 > nul

::    [English announcement]
::
::    你也可以在此处阅读 GNU Affero 通用公共许可协议的非正式中文翻译:
::    https://www.chinasona.org/gnu/agpl-3.0-cn.html
::    请注意,本翻译本仅为帮助中文使用者更好地理解 GNU Affero 通用公共许可协议,
::    不适用于使用 GNU Affero 通用公共许可协议发布的软件的法律声明。

pause

It works well in the systems with UTF-8 enabled for softwares. But in the Chinese systems (with ANSI / GB2312 charset), it will report an error '�可协议发布的软件的法律声明。' is not recognized as an internal or external command.

However, if I remove the comma () at the end of the line below the URL, like this:

::    请注意,本翻译本仅为帮助中文使用者更好地理解 GNU Affero 通用公共许可协议
::    不适用于使用 GNU Affero 通用公共许可协议发布的软件的法律声明。

It also works well, even in Chinese systems. This means that the system may recognize this comma, or other characters, as some kind of control character.

It's really a weird problem for me. I wonder, what happend with the comma?

Update:

  1. Whether I use :: or rem as the comment flag, this problem still exists.

  2. This is still a project for the whole world, although I hope it contains Chinese comments for the convenience of Chinese developers. The advice to "use code page 936 and GB2312 character set" is good, but makes no sense.

  3. We know there are many ways we can get around this problem. But for us, the more important than "how to bypass it" is "why does this happen". If we cannot figure out the reason behind the problem, the problem is not really solved.

1

There are 1 answers

0
Lurito On

A possible general solution is to add a space character at the end of each line of Chinese comments. Refer to this question body.