powershellgroovyencodingcommand-linelocale

Groovy cyrillic characters output problem


I have a problem with output in groovy script. For example this code:

def rusAlphabet = 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ'
def lowerCaseRusAlphabet = 'абвгдеёжзийклмнопрстуфхцшщъыьэюя'

println(rusAlphabet)
println(rusAlphabet.toLowerCase())
println(lowerCaseRusAlphabet)

prints:

AБВГДЕ?ЖЗИЙКЛМ?ОПРСТУФХЦЧШЩЪЫЬЭЮЯ
a??
абвгдеёжзийклмнопр?туфхцшщъыь?ю?

It works fine with Python scripts. I work on Windows 10 x64.

In CMD and PowerShell cyrillic characters were displayed as questions. Then I checked "Beta: Use Unicode UTF-8 for worldwide language support" in region administrative settings. Now it works fine, characters are displayed normally. But not for groovy scripts.

Tried this code in script:

try {
    System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out), true, "UTF-8"));
} catch (UnsupportedEncodingException e) {
    throw new InternalError("VM does not support mandatory encoding UTF-8");
}

It prints:

AБВГДЕ�ЖЗИЙКЛМ�ОПРСТУФХЦЧШЩЪЫЬЭЮЯ
að‘ð’ð“ð”ð•ð�ð–ð—ð˜ð™ðšð›ðœð�ðžðÿð ð¡ð¢ð£ð¤ð¥ð¦ð§ð¨ð©ðªð«ð¬ð­ð®ð¯
абвгдеёжзийклмнопр�туфхцшщъыь�ю�

Solution


  • [1] Note: I'm unclear on how to also switch stdin (the standard input stream) to UTF-8 for text-based operations; do tell us if you know.