4

Here is the code.

module Lib
    ( someFunc
    ) where

someFunc :: IO ()
someFunc = putStrLn "你好"

I tried to run the program in the PowerShell on Windows 10.

chcp 936
stack run

And the output is:

─π║├

Here is another try:

chcp 65001
stack run

And the output is:

你好

Any suggestion to make it work appropriately?

werewolf
  • 43
  • 4
  • 1
    The latter is this kind of [mojibake](https://en.wikipedia.org/wiki/Mojibake): `"你好".encode('utf-8').decode('cp437')` returns `'Σ╜áσÑ╜'` (example in Python as I don't speak Haskell, sorry.) And the former is analogous: `"你好".encode('cp936').decode('cp437')` returns `'─π║├'`. Check `[console]::OutputEncoding` in PowerShell. – JosefZ Jan 31 '21 at 18:37

1 Answers1

3

chcp doesn't work from inside PowerShell, due to caching performed by .NET.

You can perform an equivalent command in PowerShell as follows, using the equivalent of
chcp 65001 (changing to the UTF-8 code page) as an example:

[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = 
  [System.Text.Utf8Encoding]::new()  # BOM-less UTF-8

To get other encodings, by their Windows code-page number (or name), use [System.Text.Encoding]::GetEncoding().

See this answer for background information.

mklement0
  • 382,024
  • 64
  • 607
  • 775