0

I met some interesting question on which I was not able to find an answer. Does anybody know how to pass hieroglyphs as an argument to the main method from command line? Below there is some pseudo code which will help to test suggested solution:

public class Test {
    public static void main(String args[]) {
        if ("香港政府".equals(args[0])) {
            System.out.println("Match");
        }
    }
}

So question is how to call Test.class with an argument so the application prints Match to the console? args[0] can be transformed before passing to the if statement.

Thanks in advance.

Squashman
  • 13,649
  • 5
  • 27
  • 36
  • 4
    I think you just need to set the encoding of the console. – Sweeper Sep 06 '17 at 19:29
  • 1
    + Sweeper's comment: https://stackoverflow.com/questions/1259084/what-encoding-code-page-is-cmd-exe-using https://stackoverflow.com/questions/5306153/how-to-get-terminals-character-encoding – Mark W Sep 06 '17 at 19:31
  • @Sweeper thanks for reply, but this is very abstract answer. If you meant `chcp` I already tried `chcp 65001` - unsuccessful. `Lucida` console was also tried. – Mikita Berazouski Sep 06 '17 at 19:34
  • @MarkW thanks, I already read the articles, but still not clear how it can help in my question. Could you provide command line itself? – Mikita Berazouski Sep 06 '17 at 19:51
  • 1
    Sweeper is suggesting that whatever console you are using (CMD in windows, terminal in linux, or whatever) has an encoding on user input values that don't contain your characters. I linked some SO posts which briefly talk about the type of encoding used by windows and linux consoles, and how to set the encoding for them. Give them a once over, try to set the encoding of your console window in the ways described, and then run your app again from that console. If you're using some other console (like your IDE) you will have to find how to set the encoding for them elsewhere. – Mark W Sep 06 '17 at 20:04
  • @MarkW got it. Idea was that somebody could provide exact number for the encoding. I checked most of the codes from (Code Page Identifiers)[https://msdn.microsoft.com/en-us/library/windows/desktop/dd317756(v=vs.85).aspx] but still didn't see the chinese in console. So I need exact number instead of theory. But anyway thanks. – Mikita Berazouski Sep 06 '17 at 20:18

1 Answers1

1

After some additional research I was able kinda figured it out. So guys who commented on question were very near to the answer. Encoding which I tried to find was 936. But it doesn't mean that you will be able to run chcp 936 if you OS locale is other than chinese. Once you will try to run it on other locale than chinese:

chcp 936

You will get following error:

Invalide code page

For making it working you have to change region. FOllowing steps will be needed:

  1. Start - COntrol panel
  2. Select "Region and Language" enter image description here
  3. Select "Administrative" and click "Change system locale..." enter image description here
  4. Select "Chinese (Simplified, PRC)" and reboot laptop enter image description here

After restart when you will run chcp you will see following output Active code page: 936. Now you are ready to execute command line with hieroglyphs. enter image description here