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

White-Gandalf picture White-Gandalf · Feb 3, 2011 · Viewed 9.2k times · Source

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.

Answer

jeb picture jeb · Feb 3, 2011

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