vscode-code-runner:运行PowerShell,输出有很多奇怪的字符

问题描述 投票:0回答:1

我使用 Visual Studio code 和 Code Runner Extension 来运行 PowerShell 脚本。它可以工作,但是输出很奇怪,充满了不可读的字符。

德语元音变音不显示(下面截图中用红色箭头标记)并且有奇怪的字符(蓝色箭头):

我尝试在 settings.json 中为具有不同代码页的 Code Runner 添加字符集:

"code-runner.executorMap": { "powershell": "chcp 1252 & pwsh -ExecutionPolicy ByPass -File"}

但无济于事。 🙁

我的脚本文件都是utf8格式的并且 当我从终端窗口运行 PowerShell 和脚本时,输出看起来不错: screenshot 2

powershell visual-studio-code encoding vscode-code-runner powershell-7.3
1个回答
0
投票

Visual Studio Code 有一个专用的 PowerShell 扩展,它可以避免您面临的问题,并且 通常更可取,因为它为 PowerShell 开发和调试提供了丰富的支持


如果您仍然想使用Code Runner Extension,以下可能有帮助(未经测试):

"code-runner.executorMap": { "powershell": "chcp 65001 & set NO_COLOR=1 & pwsh -ExecutionPolicy ByPass -File"}
  • chcp 65001
    将活动代码页设置为
    65001
    ,即 UTF-8,PowerShell 在发出输出时使用该代码页。

  • 定义

    NO_COLOR
    环境变量指示 PowerShell 不要使用 ANSI/VT 转义序列对其用于显示的格式化输出进行 color(正是这些转义序列 Code Runner 不会这样渲染,导致用你的蓝色箭头)。

© www.soinside.com 2019 - 2024. All rights reserved.