从Powershell使用本机CMD命令时的编码问题 [英] Encoding issue when using Native CMD Command from Powershell
问题描述
从powershell执行本机cmd命令时,例如 net view \\192.168.1.x
,我得到以下结果,非英语字符显示为 ???? :
When Executing native cmd command from powershell, e.g net view \\192.168.1.x
I get the following results which non-English chars shown as ????
:
Share name Type Used as Comment
--------------------------------------------------
AntEater Disk
AntEater_Eab Disk
HP M4345 ????? Print HP M4345 ?????
Letters Disk
SMSCenter Disk
temp Disk
Users Disk
????? ??? ?????? Print ????? ??? ??????
The command completed successfully.
如果我运行 chcp 862
以下结果(在控制台上):
if I run chcp 862
I get the following results (on the console):
Share name Type Used as Comment
--------------------------------------------------
AntEater Disk
AntEater_Eab Disk
HP M4345 הנהחש Print HP M4345 הנהחש
Letters Disk
SMSCenter Disk
temp Disk
Users Disk
מדפסת Print
哪个还可以,但是当我尝试将其保存到变量或导出到文件时:
Which is fine, but when I try to save it to a variable or export it to a file:
$temp = net view \\192.168.1.x
$temp
Share name Type Used as Comment
--------------------------------------------------
AntEater Disk
AntEater_Eab Disk
HP M4345 ????? Print HP M4345 ?????
Letters Disk
SMSCenter Disk
temp Disk
Users Disk
????? ??? ?????? Print ????? ??? ??????
结果再次错误,
我已经尝试过:
net view \\192.168.1.x | Out-File C:\temp.txt -Encoding Unicode
cmd /c 'chcp 862 && net view \\192.168.1.x' | Out-File C:\temp.txt -Encoding Unicode
cmd /c 'chcp 862 && net view \\192.168.1.x > c:\temp.txt'
cmd /u /c 'chcp 862 && net view \\192.168.1.x > c:\temp.txt'
更多……
运行 net view \\192.168.1.x时也会显示该问题|输出字符串
相同的结果是我是从CMD还是从PowerShell运行
The same results are whether I run it from CMD or PowerShell
你知道这种行为吗?如何将正确的输出保存到变量或文件中?
Do you know the behavior? how can I save the correct output to a variable or file?
推荐答案
在更改非Unicode程序的语言后,控制面板,问题已解决,感谢您的帮助...
After changing the "language for non-Unicode programs" in the control panel, the problem solved, thanks for your help...
运行 intl.cpl
并选择 Adminstrative
标签。
这篇关于从Powershell使用本机CMD命令时的编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!