Reputation: 67
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
Upvotes: 4
Views: 4739
Reputation: 3217
$file='c:/test.txt'
# content of $file: Verknüpfung mit einem Master..
get-content $file -encoding utf8
Verknüpfung mit einem Master..
Upvotes: 0
Reputation: 1963
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 "ę"}
ę
ęę
Upvotes: 4