0

Is it possible to change the language settings for just a single process call?

In Linux i would do a LANG=C myprocess.

I need to use the java keytool, but the output is in german and contains umlauts, which is very bad to parse afterwards. Can it changed to english?

The program looks like this:

from subprocess import call, Popen, PIPE

keytool_path = "C:\\Program Files\\Java\\jdk1.7.0_13\\bin\\keytool.exe"
p = Popen([keytool_path, "-printcert", "-file", "CERT.RSA"], stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
o = out.decode("ISO-8859-1")
2
  • This works on Unix-likes because the language is set via environment variables. In Windows this is a setting on the system and user levels. Unless the application either (a) interprets LANG and/or LC_BLARGH or (b) has its own way of setting the language, you're out of luck here. Of course, you could just set your UI language to English.
    – Joey
    Jun 5, 2014 at 12:25

2 Answers 2

0

This is just not possible in Windows. Windows uses the system wide language settings, so if someone needs to have a different language output in a program that depends on these values you have to change them (-> change the whole system language)

3
  • Are you really sure ? I still have not find time to test it in Python, but Windows API as a function called SetThreadLocale to set the current locale of the calling thread. Jul 27, 2014 at 21:50
  • i only found this explaination. please post another answer if i'm wrong :)
    – reox
    Jul 28, 2014 at 7:24
  • I must acknowledge this comment has little value as SetThreadLocale cannot be used to set the locale of a subprocess under Windows :-( but see my own answer ... Jul 28, 2014 at 8:33
0

Windows is a bit tricky for that because if it is possible to change the locale of a running program by the SetThreadLocale API function (or any high level language equivalent), new processes and threads are created with default locale. So there is no way to change the locale of a subprocess by setting the locale of the parent process.

Some program (most coming from Unix or GNU world) may use LANG environment variable, but Java tools don't.

But you can force the JVM to use a particuliar language by setting the user.language system property. For a simple java program you would use java -Duser.language=en ...

For keytool utility the magic word is keytool -J-Duser.language=en

Ref : How to set default language for java keytool?

Your Answer

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

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