Powershell 无法识别特殊字符,例如:“ą”、“ę”、“ć”等。
使用类似的东西时:
PS C:\> Get-Content test.txt | findstr /c:something
??? something
PS C:\> Get-Content test.txt | findstr /c:ę => nil
正如您可能猜到的那样,任何特殊字符都会显示问号。
我过去常常运行 ruby 脚本,而当我运行
$stdin.gets.chomp
时,脚本中的每个字符都按预期工作带有特殊字符的输入显示为空框。input = $stdin.gets.chomp
puts input => ▯
它显示空方框(在早期版本的 Powershell 中,它使用问号代替)
我正在尝试 https://blogs.msdn.microsoft.com/powershell/2006/12/11/outputencoding-to-the-rescue/但这对我不起作用。
对于任何有用的建议,我将不胜感激。
编辑:将 chcp 更改为 1250 比 $OutputEncoding =[Console]::OutputEncoding
findstr/c:something 时显示“ąęą something”,但 findstr/c:ę 时不显示任何内容。在 ruby 中更改 chcp 会产生兼容性问题。
Edit2:我其余的研究都在那里Ruby compatibility error encoding
谢谢
最佳答案
尝试使用纯 powershell,不要与可执行文件混合( -match 而不是 findstr ):
Get-Content C:\temp\encoding.txt -Encoding Unicode| ? {$_ -match "ę"}
查找文件中的出现次数(当 txt 保存为 Unicode 时):
Get-Content C:\temp\encoding.txt -Encoding Unicode
ę
asd
ęę
#ääöpl
我的文件包含4行,如上图
Get-Content C:\temp\encoding.txt -Encoding Unicode| ? {$_ -match "ę"}
ę
ęę
关于Powershell(cmd too) 无法识别特殊字符 "ą, ę"等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37025963/