【发布时间】:2020-05-29 01:57:14
【问题描述】:
您好,我有一个脚本可以自动执行一些任务,在 powershell core v.7.+ 中运行。
在其中一个脚本中,当我在 ps1 文件中运行命令并且返回的特殊字符被编码并且我无法解码为正确的格式时,在用于执行此操作的命令下方并返回:
// the variable $script is my command its a ask-cli command to work in alexa
$model = pwsh -Command $script
/*
* when I running the script from here the special characters returned is these:
* "nächste",
* "nächstgelegene"
*/
但是当我直接在终端中运行相同的命令时,返回的字符串是:
/*
* "nächste",
* "nächstgelegene"
*/
我想知道如何在不编码返回的情况下在文件中运行命令。 我已经尝试了一些方法:
$encoding = [System.Text.Encoding]::Unicode
$model = pwsh -Command $script
Write-Output $model
$model = $encoding.GetBytes($model)
$model = $encoding.GetString($model)
但是没有按预期工作,我不知道该怎么做,如果有人可以帮助我,我非常感激。
【问题讨论】:
标签: powershell character-encoding special-characters powershell-core