1

Is there a way to detect the character encoding set in the terminal which is calling my Java program? In Windows I can call the "chcp" tool and parse the output.

But what about in Linux or Mac?

0

2 Answers 2

2

Check the locale(1) man page

You can change this by setting the LANG environment variable

$ export LANG=en_US.iso88591

$ locale
LANG=en_US.iso88591
LC_CTYPE="en_US.iso88591"
LC_NUMERIC="en_US.iso88591"
LC_TIME="en_US.iso88591"
LC_COLLATE="en_US.iso88591"
LC_MONETARY="en_US.iso88591"
LC_MESSAGES="en_US.iso88591"
LC_PAPER="en_US.iso88591"
LC_NAME="en_US.iso88591"
LC_ADDRESS="en_US.iso88591"
LC_TELEPHONE="en_US.iso88591"
LC_MEASUREMENT="en_US.iso88591"

LC_IDENTIFICATION="en_US.iso88591"

Sign up to request clarification or add additional context in comments.

1 Comment

Better than nothing...the problem is that locale gives the same output even after changing the terminal encoding... it simply gives the default console encoding for new consoles...
1

There is no defined communication path from the terminal app to processes running inside a terminal window (short of those defined by the terminal being emulated, such as window size changes). This would be true on any other Unix-like OS as well. Environment variables can only be inherited when a process starts. Looking at the values of these environment variables is all you can do.

Do you really expect people to be changing the encoding while a terminal window is open? I can't imagine this is a common use case at all.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.