Forum Stats

  • 3,751,483 Users
  • 2,250,366 Discussions
  • 7,867,436 Comments

Discussions

JShell encoding in DOS/Windows

jkostaras-JavaNet
jkostaras-JavaNet Member Posts: 3
edited Feb 22, 2020 7:14AM in Java SE Early Access

Hallo,

I was wondering if anybody has encountered the issue of using non-english letters in jshell on windows. On linux or mac jshell behaves correctly.

In a DOS window, I try to enter Greek letters, e.g.:

jshell> var s = "Γειά"

but I can only see

jshell> var s = "????"

I thought that it has to do with the locale or character set.

DOS> chcp437 

so I changed it to UTF-8

DOS> chcp65001

hoping that this would fix the problem, but alas. Please note that in DOS (outside of jshell) I can type Greek letters without an issue.

Even the JShell from inside NetBeans:

[1]-> String s = "Γειά σου";|  s ==> "???? ???"

So I was wondering if there is some way to set the encoding in JShell itself.

Please note that this behaviour exists only on JShell on Windows. The OS locale has been changed to support the Greek language. However, JShell doesn't want to comply.

Any suggestions are highly appreciated.

Regards,

John.

Answers

  • d65ad744-1d9b-42ab-8fc0-54577dd383fb
    edited Dec 4, 2019 2:52PM

    I have the equivalent problem with German settings.

    It works fine under Linux (xUbuntu 18.04) but on Windows10, there are problems with non-US-characters.

    If I type in the REPL (aka JShell)

    > println ("ÄÖÜäöü߀")

    I can see it exactly as written and expected/hoped for, but the feedback, when hitting ENTER, is funky characters, question marks upside down and the like - I'm now not on the machine with this error, else I would post the exact output.

    If I write the command in notepad++ and save it to a file, sample.java, and load it into rhe REPL with

    > /open sample.java

    I have the same issues, but I can change the encoding in notepad++ to OEM850, CP1252 which used to be used with Win95/98 afaik, and with OEM(?)850 I get close: Only the small ü and the Euro-Symbol fail. But that seems to be an ancient approach - shouldn't UTF-8 work for all Western-European Countries, the US, Australia, most African Countries and South-Amerika, except from newline-issues with Windows, Mac and Linux?

    However, notepad++ add a BOM to the file and the BOM creates new problems. Sadly I don't remember which exactly.

    I guess jkostaras-JavaNet is referring to cmd.exe, when talking about the "DOS-Window". It's not a DOS-Window.

    I tested it with cmd.exe and Powershell and just starting JShell from the Windowsmenu - that didn't make a difference.

    I looked for a promising switch to change the encoding but didn't find anything. Now, on my Linuxmachine, where I don't have these issues, I suspect I might should try the -J -switch on jshell-startup, but I'm unsure what I shall try -

    * file.encoding = UTF-8

    * sun.jnu.encoding = UTF-8

    * user.language = de

    * user.country = DE

    * default display locale = Deutsch (Deutschland)

    and how, or something else?

  • jkostaras-JavaNet
    jkostaras-JavaNet Member Posts: 3
    edited Dec 9, 2019 3:52PM

    I came across this (RFR: JDK-8166535: jshell tool: cannot handle non-ascii characters) that confirms that there is indeed an issue with JShell on Windows. Bug

    https://bugs.openjdk.java.net/browse/JDK-8166535 is resolved but... Funny that in the comments they mention that the original problem was reported on Windows, but they test it on Mac/Linux and then they close the ticket!

  • virxen75
    virxen75 Member Posts: 1
    edited Feb 22, 2020 7:14AM

    1) set system enviroment variable  JAVA_TOOL_OPTIONS=-Dfile.encoding=utf8

    2)execute chcp 65001 before jshell  or add it to registry(see photo below)

    3)files loaded in jshell (/open command) must be saved in utf8 encoding without BOM (you can use notepad++ for this)

    j5.jpg