![](/img/trans.png)
[英]How to read a file in utf8 encoding and output in Windows 10?
[英]Use Haskell to Output Utf8 String in the PowerShell on Windows 10
這是代碼。
module Lib
( someFunc
) where
someFunc :: IO ()
someFunc = putStrLn "你好"
我嘗試在 Windows 10 上的 PowerShell 中運行程序。
chcp 936
stack run
output 是:
─π║├
這是另一個嘗試:
chcp 65001
stack run
output 是:
你好
有什么建議可以讓它正常工作嗎?
由於 .NET 執行緩存, chcp
在 PowerShell內部不起作用。
您可以在 PowerShell 中執行等效命令,如下所示,使用等效的
以chcp 65001
(更改為 UTF-8 代碼頁)為例:
[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding =
[System.Text.Utf8Encoding]::new() # BOM-less UTF-8
要通過其 Windows 代碼頁號(或名稱)獲取其他編碼,請使用[System.Text.Encoding]::GetEncoding()
。
有關背景信息,請參閱此答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.