Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何解决powershell中的字符串编码问题?_Powershell_Utf 8_Utf 16 - Fatal编程技术网

如何解决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空格。相关: