Powershell(cmd too) doesn't recognize special characters “ą, ę” etc

老子叫甜甜 提交于 2020-01-15 04:25:48

问题


Powershell does not recognize special characters such as: "ą", "ę", "ć" etc. when using something like that:

PS C:\> Get-Content test.txt | findstr /c:something

??? something 

PS C:\> Get-Content test.txt | findstr /c:ę => nil

As you mayguess any special character will show question mark.

I use to run ruby scripts and while every character from script is working as intended when i run $stdin.gets.chomp the input with special character is showing as empty box.

input = $stdin.gets.chomp

puts input => ▯

And it shows empty square box (with earlier version of Powershell it used question marks instead)

I was trying https://blogs.msdn.microsoft.com/powershell/2006/12/11/outputencoding-to-the-rescue/ but that does not work for me.

For any helpful advice i will be thankful.

Edit: Changing chcp to 1250 than $OutputEncoding =[Console]::OutputEncoding shows "ąęą something" when findstr /c:something but doesn't show anything when findstr /c:ę. Changing chcp creates compability issues when in ruby.

Edit2: Rest of my researches goes there Ruby compatibility error encoding

Thanks


回答1:


Try using pure powershell, not mixing with executables (-match instead of findstr):

Get-Content C:\temp\encoding.txt -Encoding Unicode| ? {$_ -match "ę"}

Finds occurences in the file (when txt is saved as Unicode):

Get-Content C:\temp\encoding.txt -Encoding Unicode

ę 
asd
ęę
#ääöpl

My file contained 4 lines, as shown above

Get-Content C:\temp\encoding.txt -Encoding Unicode| ? {$_ -match "ę"}

ę 
ęę


来源:https://stackoverflow.com/questions/37025963/powershellcmd-too-doesnt-recognize-special-characters-%c4%85-%c4%99-etc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!