如何解决powershell中的字符串编码问题?
我有以下命令:如何解决powershell中的字符串编码问题?,powershell,utf-8,utf-16,Powershell,Utf 8,Utf 16,我有以下命令: &wsl--execbash-c“echo Hello”|输出字符串 在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
&wsl--execbash-c“echo Hello”|输出字符串
在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),我不知道它是哪种编码:使用Out file-FilePath\u输出路径\-encoding utf8
。设置默认环境值:
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
.Net(以及Powershell)的内部编码是UTF 16。所以“a”实际上是0x0061
,零变成了e x t r a空格。相关: