Results 1 to 9 of 9
  1. #1
    phkoester is offline Member
    Join Date
    May 2011
    Posts
    5
    Rep Power
    0

    Default 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

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    It has nothing to do with Java, it has to do with "Windows stupid console".

  3. #3
    phkoester is offline Member
    Join Date
    May 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    It has nothing to do with Java, it has to do with "Windows stupid console".
    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'.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    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)?

  5. #5
    phkoester is offline Member
    Join Date
    May 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    And all of those programs you used to accomplish that little test were written by who?
    By me. No other tools than `cmd', `java', and `javac' involved. How could I make that any purer?

    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)?
    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.

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by phkoester View Post
    By me. No other tools than `cmd', `java', and `javac' involved. How could I make that any purer?
    I meant, of course, the "successful" test.
    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.
    Java is the implied "third-party software" that isn't paying hefty fees to Microsoft, of course.

    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.

  7. #7
    phkoester is offline Member
    Join Date
    May 2011
    Posts
    5
    Rep Power
    0

    Default

    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.

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    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.

  9. #9
    phkoester is offline Member
    Join Date
    May 2011
    Posts
    5
    Rep Power
    0

    Default

    Hm, bugs.sun.com seems terribly slow. Am I looking in the wrong place? Just wanted to check if my bug report has been approved yet.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •