views:

3450

answers:

4

We try to use Java and UTF-8 on Windows. The application writes logs on the console, and we would like to use UTF-8 for the logs as our application has internationalized logs.

It is possible to configure the JVM so it generates UTF-8, using -Dfile.encoding=UTF-8 as arguments to the JVM. It works fine, but the output on a Windows console is garbled.

Then, we can set the code page of the console to 65001 (chcp 65001), but in this case, the .bat files do not work. This means that when we try to launch our application through our script (named start.bat), absolutely nothing happens. The command simple returns:

C:\Application> chcp 65001
Activated code page: 65001
C:\Application> start.bat

C:\Application>

But without chcp 65001, there is no problem, and the application can be launched.

Any hints about that?

Thanks in advance.

+1  A: 

Just a wild guess: Could windows be mad about start.bat not being of code page 65001 ?

svrist
A: 

Have you tried PowerShell rather than old cmd.exe.

sblundy
+1  A: 

Try chcp 65001 && start.bat

erickson
A: 

We had some similar problems in Linux. Our code was in ISO-8859-1 (mostly cp-1252 compatible) but the console was UTF-8, making the code to not compile. Simply changing the console to ISO-8859-1 would make the build script, in UTF-8, to break. We found a couple of choices:
1- define some standard encoding and sticky to it. That was our choice. We choose to keep all in ISO-8859-1, modifying the build scripts.
2- Setting the encoding before starting any task, even inside the build scripts. Some code like the erickson said. In Linux was like :

lang=pt_BR.ISO-8859-1 /usr/local/xxxx

My eclipse is still like this. Both do work well.

Renato Soffiatto
Seems like a step backwards to stick (and modify things) to iso-8859-1 instead of utf-8 . But probably You had your reasons.
karolrvn