3

I want to run a command line programme on Windows, here is the code.

    public static String runcmd(String cmd) throws IOException {
    ProcessBuilder builder = new ProcessBuilder(cmd);
    builder.redirectErrorStream(true);
    Process p = builder.start();
    BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    StringBuilder sb = new StringBuilder();
    while (true) {
        line = r.readLine();
        if (line == null)
            break;
        sb.append(line + "%SKIPLINE%");
    }
    System.out.println(sb.toString());
    return sb.toString();
}

Everything work fine, except that it prints out the output in Chinese because my Windows language is set to Chinese. Is there any ways to make it output in English?

RandomGuy
  • 75
  • 8

2 Answers2

1

Try this:

https://wandersick.blogspot.com/p/change-non-english-command-line.html

Or Execute

chcp 437 in the cmd prompt.

For example:

C:\Users\javaserv> chcp 437
Active code page: 437

Hope it helps!

Philzen
  • 3,945
  • 30
  • 46
  • Its better to show some code or notes before referencing so that there would still be something to read even if the link is removed. – Young Emil Sep 19 '16 at 17:59
1

Check this link: how to detect operating system language (locale) from java code

What you want to find is a way to temporarily set your locale in the program to English.

Community
  • 1
  • 1
Sandy Simonton
  • 604
  • 5
  • 15