Win 安装新版 PowerShell(PowerShell 7)
winget install --id Microsoft.PowerShell --source winget设置UTF-8编码
用 PowerShell 7 打开后执行:
notepad $PROFILE把下面这段放进去:
# 控制台输入/输出编码
[Console]::InputEncoding = [System.Text.UTF8Encoding]::new()
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
# 外部程序管道/重定向时的编码(影响与外部命令交互)
$OutputEncoding = [System.Text.UTF8Encoding]::new()
# 让 Out-File / 重定向 > >> 默认用 utf8(可选,但很实用)
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
$PSDefaultParameterValues['*:Encoding'] = 'utf8'设置vscode默认执行类命令行为新版powershell
修改vscode的settings.json
{
// 仅用于 tasks/debug/自动化 的默认 shell:指定 PowerShell 7
"terminal.integrated.automationProfile.windows": {
"path": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
"args": ["-NoLogo"]
}
}测试
"中文测试" | Out-File test.txt
Get-Content test.txt
Comment here is closed