这里是代码。
module Lib
( someFunc
) where
someFunc :: IO ()
someFunc = putStrLn "你好"
我尝试在Windows 10上的PowerShell中运行该程序。
chcp 936
stack run
输出结果为:
─π║├
这是另一次尝试:
chcp 65001
stack run
输出结果为:
你好
有什么建议可以让它正常工作?
这里是代码。
module Lib
( someFunc
) where
someFunc :: IO ()
someFunc = putStrLn "你好"
我尝试在Windows 10上的PowerShell中运行该程序。
chcp 936
stack run
输出结果为:
─π║├
chcp 65001
stack run
输出结果为:
你好
有什么建议可以让它正常工作?
chcp
命令不起作用是因为 .NET 进行了缓存,这种情况发生在 PowerShell 内部。
你可以在 PowerShell 中执行等效的命令,例如将编码更改为 UTF-8(chcp 65001
):
[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding =
[System.Text.Utf8Encoding]::new() # BOM-less UTF-8
[System.Text.Encoding]::GetEncoding()
。有关背景信息,请参见此答案。
"你好".encode('utf-8').decode('cp437')
返回'Σ╜áσÑ╜'
(这里用 Python 举例,因为我不会 Haskell,抱歉)。前者类似:"你好".encode('cp936').decode('cp437')
返回'─π║├'
。 在 PowerShell 中,检查[console]::OutputEncoding
。 - JosefZ