Results 1 to 9 of 9
Thread: Java, `cmd.exe', and UTF-8
- 05-07-2011, 05:58 PM #1
Member
- Join Date
- May 2011
- Posts
- 5
- Rep Power
- 0
Java, `cmd.exe', and UTF-8
To the best of my knowledge it has never worked to print UTF-8 to a Windows console.
Let's take the following example string: " »« © ← → ↑ ↓ 奥" (the last char being troublesome Chinese).
As I understand it, `chcp 65001' tells `cmd.exe' to be UTF-8-encoded.
Now I have this class:
public class Foo {
public static void main(String[] args) {
System.out.println("file.encoding=" + System.getProperty("file.encoding"));
System.out.println(" »« © ← → ↑ ↓ 奥");
}
}
Compile and run it like this:
> javac -encoding utf8 Foo.java
> cchcp 65001
> java -Dfile.encoding=UTF-8 Foo
I expect this to work, but it doesn't. As it turns out, the characters are displayed correcly but then followed by clutter. The output I get is the following:
»« © ← → ↑ ↓ 奥� © ← → ↑ ↓ 奥→ ↑ ↓ 奥 ↓ 奥 奥��
This is not quite want I wanted.
I don't know what you think, but it's 2011 AD and I find it quite embarrassing that Java still isn't able to write UTF-8 to a Windows console.
Now who is to blame? Is it `cmd.exe' (which is, as I have proven, UTF-8-compliant), is it me, or is this really a JDK/JRE bug?
I filed a bug report today, but maybe someone out there knows how I can print UTF-8 to a Windows console. I can't figure it out and give up.
And yeah, I'm new to this forum, so hello everybody
Philip
- 05-07-2011, 07:12 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
It has nothing to do with Java, it has to do with "Windows stupid console".
- 05-07-2011, 07:30 PM #3
Member
- Join Date
- May 2011
- Posts
- 5
- Rep Power
- 0
Are you sure?
Save a file called `foo.cmd', UTF-8-encoded, like this
@echo off
chcp 65001
echo »« © ← → ↑ ↓ 奥
and you will discover that it works perfectly. I am not 100 % sure, but I think this time it is not Microsoft that is to blame but the Sun's (Oracle's) JRE encoding scheme.
As far as I can see, `cmd.exe' is not the bad guy this time. I suspect it's `java.exe'.
- 05-07-2011, 07:35 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
And all of those programs you used to accomplish that little test were written by who?
And what happens as soon as a third-party software attempts to do anything beyond the "ordinary" (when the company that produced that software is not paying hefty license fees to that original company)?
- 05-07-2011, 07:57 PM #5
Member
- Join Date
- May 2011
- Posts
- 5
- Rep Power
- 0
By me. No other tools than `cmd', `java', and `javac' involved. How could I make that any purer?
I'm not talking about 3rd-party software. I am talking about my inablility to output UTF-8 on a Windows console and am wondering which company I should send a bug report.And what happens as soon as a third-party software attempts to do anything beyond the "ordinary" (when the company that produced that software is not paying hefty license fees to that original company)?
- 05-07-2011, 08:01 PM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
I meant, of course, the "successful" test.
Java is the implied "third-party software" that isn't paying hefty fees to Microsoft, of course.I'm not talking about 3rd-party software. I am talking about my inablility to output UTF-8 on a Windows console and am wondering which company I should send a bug report.
Place a bug report to both, of course. The worst that will happen is that both will say it is the other's fault, which is, almost assuredly, what will happen.
- 05-07-2011, 08:17 PM #7
Member
- Join Date
- May 2011
- Posts
- 5
- Rep Power
- 0
Alright, now I gotcha. Well, as a matter of fact, I don't suspect company wars this time but only a sloppy JRE implementation made by Oracle (still can't get used to the fact Sun was bought by Oracle, damn). I'll wait for Oracle's answer and address Microsoft afterwards. But I'm pretty damn sure this is an old JRE bug nobody so far had the enthusiasm to follow.
- 05-07-2011, 08:20 PM #8
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
I don't interpret it as the implentation being "sloppy". I interpret it as MS not supplying the necessary information to be able to do it correctly.
- 05-12-2011, 03:36 PM #9
Member
- Join Date
- May 2011
- Posts
- 5
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks