9

How to make the following code work with Unicode (CJK) in Command Prompt/LameShell?

main = getLine >>= putStrLn

(Windows 8.1, Haskell Platform 2014)

No, chcp 65001 doesn't work, nor chcp 10000.

No, I don't want to change System Local (Control Panel/Clock, Language, and Region/Language/Change date, time, or number formats/Administrative) from English(United States) to others.

Yes, I have set font to Lucida Console.

I've tried ConEmu/Cmder/Console2, they all said "Exception: : hGetLine: end of file". I also tried Emacs, (I use Vim), it didn't crash, but I always get spaces, no matter what I input.

Patch GHC and recompile it is acceptable, if there is no other way.

Any idea?

Thanks.

Not an ID
  • 2,579
  • 2
  • 21
  • 28
  • Have you tried `hSetEncoding` from in `System.IO`? – Arnon Feb 28 '15 at 10:44
  • Don't work. After `chcp 65001`, `hGetEncoding stdin` already gives me `Just UTF-8`, I just did a `hSetEncoding stdin utf8` anyway, no luck. – Not an ID Feb 28 '15 at 10:48
  • I've had this problem on CentOS before and I had it solved with hSetEncoding. It doesn't appear to be working in my Windows 8 either.... It's really bizzare. Perhaps patching GHC is the correct way to deal with it for now. – Arnon Feb 28 '15 at 11:00
  • Thanks anyway. This seems to be an obvious bug, I just don't believe that it hasn't been fixed already. – Not an ID Feb 28 '15 at 11:02
  • This might be a duplicate of [Unicode console I/O in Haskell on Windows](http://stackoverflow.com/questions/10779149/unicode-console-i-o-in-haskell-on-windows). – Cirdec Mar 01 '15 at 02:36

1 Answers1

1

PowerShell supports UTF natively. Assuming I understand your example (main = getLine >>= putStrLn) properly:

$var = Read-Host
Write "$var"

Or simply:

Read-Host
Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63