18

I wrote a small Java application which output includes Unicode characters. When I use Eclipse to run it—I see all the output as expected.

The people who are supposed to use the application will run it as a jar file. I thought they could use standard cmd window, but in this window the Unicode appear as Gibberish.

Is there a way to make "cmd window" recognize the Unicode chars and display them properly? Or, is there any tool to easily run the jar file and get the correct output?

BTW - redirecting the output to a file works okay, but the program is interactive, so this will not be a good solution.

Edit: Thanks everybody for the suggestions. It seems that the cmd fonts don't have the specific characters I need, and this is why changing the code page did not solve my problem.

I found a way to add more monospaced fonts to the console, but after I add them any change that I want to do regarding the fonts (even choosing one of the original fonts in a different size) - is ignored.

I think that I will simply try with another tool, which supports chhosing a differnt font more easily.

3
  • I suppose you'll have to write a "console" for your application after all...
    – maxwellb
    Aug 4, 2009 at 14:59
  • "way to add more monospaced fonts to the console" - the link is dead
    – mbomb007
    Mar 1, 2018 at 15:36
  • Here is a way to add more fonts. Not sure if it has the problem the OP mentioned anymore, though.
    – mbomb007
    Mar 1, 2018 at 15:41

6 Answers 6

17

Reference: Java Unicode on Windows Command Line

Try chcp 1252 or chcp 65001 from the command line. With Lucida Console or other font support.

1
  • chcp 65001 helped in Windows 11 cmd.exe (command prompt), but not in wt.exe (PowerShell).
    – Bob Stein
    Sep 13, 2022 at 11:47
1

try CMD /c /U java your.jar

2
  • This did not solve the problem... As far as I understand, /U influence only output of internal commands.
    – Dikla
    Jun 23, 2009 at 22:29
  • 2
    Also, would be cmd /U /c, otherwise "/U is not recognized as an internal or external command".
    – maxwellb
    Jun 24, 2009 at 0:06
1

The problem is the font with which the windows console is displaying output. Unfortunately for you, this is a user setting.

I recommend you suggest that your users set their windows console font to Lucida Console. That font should be able to handle wide/unicode characters.

4
  • 3
    Even in Windows 7 the console windows default to raster fonts :-(. Very unfortunate.
    – Joey
    Jun 23, 2009 at 22:19
  • 4
    I changed the font to Lucida. This did not solve the problem :(
    – Dikla
    Jun 23, 2009 at 22:24
  • Thanks for the feedback Dikla. I clicked -1 since this in fact, does not help.
    – maxwellb
    Jun 23, 2009 at 23:56
  • 2
    offtopic, but i think i prefer the look of raster :)
    – user47322
    Jun 24, 2009 at 0:11
1

In C++/C just use this: system("chcp 65001");

Don't forget to change the console's font to Lucida Console

0

For any answers, check it first. This is a simple console program, which verifies that changing the font actually does not work.

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main( string[] args )
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            Console.WriteLine( "日本語です" );
            Console.Write( "Finished. Press a key. " );
            Console.ReadLine();
            return;
        }
    }
}

I will check to see if the answer is concretely "Cannot be done". Other avenues to check: use a different shell. i.e. Powershell? I'll see if that works.

However, you could do:

ConsoleApplication1.exe > output.txt
notepad.exe output.txt

Disclaimer: My example is C#, but the console application should still work as such.

And view the results like that, in the meanwhile.

0
0

UTF-16 on cmd.exe

    Open/run cmd.exe
    Click on the icon at the top-left corner
    Select properties
    Then "Font" bar
    Select "Lucida Console" and OK.
    Write Chcp 10000 at the prompt
    Finally dir /b

Also from Is there a Windows command shell that will display Unicode characters?

CHCP 65001
DIR > UTF8.TXT
TYPE UTF8.TXT
1
  • 3
    Does "Lucida Console" supports special chars? I tried several chars and they were displayed as a squares on the cmd window.
    – Dikla
    Jun 12, 2014 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.