【问题标题】:How to fix Out-String encoding issues in powershell?如何修复 Powershell 中的 Out-String 编码问题?
【发布时间】:2020-10-28 11:41:50
【问题描述】:

我有以下命令:

& wsl --exec bash -c "echo Hello" | Out-String

在 Powershell 控制台中返回一个完全奇怪的格式化字符串:

P l e a s e   e n a b l e   t h e   V i r t u a l   M a c h i n e   P l a t f o r m   W i n d o w s   f e a t u r e   a n d   e n s u r e   v i r t u a l i z a t i o n   
i s   e n a b l e d   i n   t h e   B I O S .


 F o r   i n f o r m a t i o n   p l e a s e   v i s i t   h t t p s : / / a k a . m s / w s l 2 - i n s t a l l

如何解决这些编码问题?当我将它写入带有& wsl --exec bash -c "exit 0" | Out-String > Log 的文件时,它包含 carbage unicode(上面的 whitspace),我不知道它是哪种编码:

【问题讨论】:

标签: powershell utf-8 utf-16


【解决方案1】:

请改用Out-File -FilePath \YOUR_OUTPUT_PATH\ -Encoding utf8

【讨论】:

    【解决方案2】:

    设置默认环境值:

    $PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 2020-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多