windows - 在 Windows 10 上的 PowerShell 中使用 Haskell 输出 Utf8 字符串

标签 windows powershell haskell utf-8

这是代码。

module Lib
    ( someFunc
    ) where

someFunc :: IO ()
someFunc = putStrLn "你好"
我尝试在 Windows 10 上的 PowerShell 中运行该程序。
chcp 936
stack run
输出是:
─π║├
这是另一个尝试:
chcp 65001
stack run
输出是:
你好
有什么建议可以使它正常工作吗?

最佳答案

chcp由于 .NET 执行的缓存,在 PowerShell 内部不起作用。
您可以在 PowerShell 中执行等效的命令,如下所示,使用等效的命令chcp 65001 (更改为 UTF-8 代码页)作为示例:

[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = 
  [System.Text.Utf8Encoding]::new()  # BOM-less UTF-8
要获得其他编码,通过它们的 Windows 代码页号(或名称),使用 [System.Text.Encoding]::GetEncoding() .
this answer背景信息。

关于windows - 在 Windows 10 上的 PowerShell 中使用 Haskell 输出 Utf8 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65982138/

相关文章:

powershell - 如何通过脚本查看虚拟硬盘的分区数?

windows - 通过cmd/batch/powershell启用Windows 10内置热点

haskell - 以foldr 来定义scanr 是如何工作的?

java - mailto URI 在 Java.Desktop 和 Windows/MS outlook 之间被截断

windows - 将 powerpoint 中的内部图像转换为一种格式

visual-studio - 使用 PowerShell 和 TFS.exe 更新和删除项目中的文件

haskell 埃森 : How to get value out of Parser in IO monad

haskell - 从 Haskell 中的 'a' 返回类型获取 'Maybe a' 值

python - Windows 机器上 IPython 控制台中的多处理 - 如果 __name_ 要求

.net - SystemInformation.ComputerName、Environment.MachineName 和 Net.Dns.GetHostName 之间的区别