Powershell(cmd too) doesn't recognize special

2019-07-12 05:04发布

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条回答
欢心
2楼-- · 2019-07-12 05:37

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 "ę"}

ę 
ęę
查看更多
登录 后发表回答