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")
senderle
  • 145,869
  • 36
  • 209
  • 233
reox
  • 5,036
  • 11
  • 53
  • 98
  • 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 05 '14 at 12:25
  • See [how do I set the default locale for my JVM?](http://stackoverflow.com/q/8809098/222914) – Janne Karila Jun 05 '14 at 12:32

2 Answers2

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)

reox
  • 5,036
  • 11
  • 53
  • 98
  • 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. – Serge Ballesta Jul 27 '14 at 21:50
  • i only found this explaination. please post another answer if i'm wrong :) – reox Jul 28 '14 at 07: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 ... – Serge Ballesta Jul 28 '14 at 08: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?

Community
  • 1
  • 1
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252