PowerShell(也是如此)不识别特殊字符&ą,ę和其他 [英] Powershell(cmd too) doesn't recognize special characters "ą, ę" etc

查看:60
本文介绍了PowerShell(也是如此)不识别特殊字符&ą,ę和其他的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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,而不是$OutputEnding=[控制台]::OutputEnding 在查找str/c时显示"ąęąSomething",但在查找str/c:ę时不显示任何内容。在Ruby中更改chcp会导致兼容性问题。

Edit2:我的其余研究都在那里Ruby compatibility error encoding

谢谢

推荐答案

尝试使用纯PowerShell,不要与可执行文件混合(-匹配而不是findstr):

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

在文件中查找匹配项(当txt另存为Unicode时):

Get-Content C:	empencoding.txt -Encoding Unicode

ę 
asd
ęę
#ääöpl

我的文件包含4行,如上图所示

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

ę 
ęę

这篇关于PowerShell(也是如此)不识别特殊字符&ą,ę和其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆