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.

Keith Pinson
  • 7,835
  • 7
  • 61
  • 104
Dikla
  • 3,461
  • 5
  • 30
  • 43
  • I suppose you'll have to write a "console" for your application after all... – maxwellb Aug 04 '09 at 14:59
  • "way to add more monospaced fonts to the console" - the link is dead – mbomb007 Mar 01 '18 at 15:36
  • [Here](https://www.techrepublic.com/blog/windows-and-office/quick-tip-add-fonts-to-the-command-prompt/) is a way to add more fonts. Not sure if it has the problem the OP mentioned anymore, though. – mbomb007 Mar 01 '18 at 15:41

6 Answers6

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.

maxwellb
  • 13,366
  • 2
  • 25
  • 35
1

try CMD /c /U java your.jar

Shay Erlichmen
  • 31,691
  • 7
  • 68
  • 87
  • This did not solve the problem... As far as I understand, /U influence only output of internal commands. – Dikla Jun 23 '09 at 22:29
  • 2
    Also, would be cmd /U /c, otherwise "/U is not recognized as an internal or external command". – maxwellb Jun 24 '09 at 00: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.

Randolpho
  • 55,384
  • 17
  • 145
  • 179
1

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

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

Behrouz.M
  • 3,445
  • 6
  • 37
  • 64
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.

maxwellb
  • 13,366
  • 2
  • 25
  • 35
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
Community
  • 1
  • 1
user2718593
  • 111
  • 8
  • 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 '14 at 15:09