Windows XP - cmd.exe - Cannot execute batch file after switching to utf8 codepage

梦想的初衷 提交于 2019-12-13 14:33:12

问题


After switching to utf8 codepage with "mode con cp select=65001", batch processing seams to stop working without any error messages.

Thus, executing "cmd.exe /c test.bat" in a freshly started console with codepage 437 or 850 being active works fine. Executing "mode con cp select=65001" works fine. Display of UTF-8-characters works fine. Executing something like "echo Hallo!" works fine.

But executing "cmd.exe /c test.bat" stops working with no error message displayed.

It's not only a display error: The batch file does not get executed.

Switching back to any "old" character set lets it work fine again. Switching forth to UTF8 character set lets it stop working again.

Of course, abstaining from UTF8 IS a solution - but with bad side effects in the background.


回答1:


I don't know how you can start a batch file after the codepage is changed to 65001.
Even if you save the batch file in utf16-le or utf16-be it doesn't start.

But you can run a batch file and change the codepage inside,
but it is important that the rest of the code is cached in a block (parenthesis or ampersand line).

@echo off
(
chcp 65001
rem Do my UTF work
chcp 850
)
echo This works

chcp 65001 & type myFile & chcp 850
echo This also works


来源:https://stackoverflow.com/questions/4882518/windows-xp-cmd-exe-cannot-execute-batch-file-after-switching-to-utf8-codepag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!