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/ https://blogs.msdn.microsoft.com/powershell/2006/12/11/outputencoding-to-the-rescue/但这对我不起作用。
对于任何有用的建议,我将不胜感激。
编辑:将 chcp 更改为 1250 比 $OutputEncoding =[Console]::OutputEncoding
当 findstr /c:something 时显示“ąęą Something”,但当 findstr /c:something 时不显示任何内容。在 ruby 中更改 chcp 会产生兼容性问题。
Edit2:我的其余研究都在那里Ruby 兼容性错误编码 https://stackoverflow.com/questions/37029914/ruby-compatibility-error
Thanks
尝试使用纯 powershell,而不是与可执行文件混合(-match代替findstr):
Get-Content C:\temp\encoding.txt -Encoding Unicode| ? {$_ -match "ę"}
查找文件中的匹配项(当文本保存为 Unicode 时):
Get-Content C:\temp\encoding.txt -Encoding Unicode
ę
asd
ęę
#ääöpl
我的文件包含 4 行,如上所示
Get-Content C:\temp\encoding.txt -Encoding Unicode| ? {$_ -match "ę"}
ę
ęę
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)