Powershell(cmd too) 无法识别特殊字符 "ą, ę"等

标签 powershell special-characters

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/

相关文章:

powershell - 如何将 Export-CSV 链接到 Send-MailMessage 而不必在 PowerShell 中将 CSV 保存到磁盘?

Powershell Web 访问导致 404

powershell - 验证数组参数的模式

c# - 在 .Net 应用程序中使用/显示来自 Oracle 数据库的特殊字符时遇到问题

php - 在 MySQL 中存储注释和特殊字符或 RTF

powershell - PowerShell无法识别基本命令?术语 'get'无法识别为cmdlet的名称(错误)

Mysql:将带有特殊字符的记录链接到特殊字符之后的第一个字母并检索

vb.net - FTP 文件中的特殊字符

bash - 如何知道bash中[ENTER]和[SPACE]之间的区别

powershell - 从 CMD 调用 powershell.exe 并退出代码 boolean