Install
openclaw skills install chinese-encoding-handler解决PowerShell环境中文文件乱码,支持自动编码检测、安全读写及终端中文显示修复。
openclaw skills install chinese-encoding-handler中文编码处理工具包,解决 PowerShell 环境下中文文件读写乱码问题。提供自动编码检测、安全文件读写和终端显示修复功能。
.\scripts\encoding-detector.ps1 -Path "C:\path\to\file.txt"
输出示例:
文件路径:C:\path\to\file.txt
检测编码:UTF-8-BOM
置信度:100%
.\scripts\safe-read.ps1 -Path "C:\path\to\file.txt"
带编码参数读取:
.\scripts\safe-read.ps1 -Path "C:\path\to\file.txt" -Encoding "UTF-8"
.\scripts\safe-write.ps1 -Path "C:\path\to\file.txt" -Content "中文内容"
指定编码写入:
.\scripts\safe-write.ps1 -Path "C:\path\to\file.txt" -Content "中文内容" -Encoding "UTF-8-BOM"
.\scripts\terminal-fix.ps1
永久修复(需要管理员权限):
.\scripts\terminal-fix.ps1 -Permanent
BOM 检测:优先检查文件开头的字节顺序标记(BOM)
EF BB BFFF FEFE FF内容分析:无 BOM 时,通过字节分布和常见中文字符编码特征判断
置信度评分:根据匹配程度给出 0-100% 置信度
| 系统 | 支持程度 | 备注 |
|---|---|---|
| Windows PowerShell 5.1 | ✅ 完全支持 | 推荐 UTF-8-BOM |
| Windows PowerShell 7+ | ✅ 完全支持 | 默认 UTF-8 |
| Linux/macOS | ✅ 支持 | 建议无 BOM UTF-8 |
| CI/CD 环境 | ✅ 支持 | 需确保终端 UTF-8 |
Q1: 为什么读取文件还是乱码?
-Encoding 参数encoding-detector.ps1 重新检测Q2: 写入的文件在记事本打开乱码?
-Encoding "UTF-8-BOM" 参数Q3: PowerShell 终端显示中文为方框?
terminal-fix.ps1-Permanent 参数永久修复Q4: 批量处理文件时部分失败?
| 错误码 | 含义 | 解决方案 |
|---|---|---|
| ERR-001 | 文件不存在 | 检查路径是否正确 |
| ERR-002 | 权限不足 | 以管理员身份运行 |
| ERR-003 | 编码检测失败 | 手动指定编码参数 |
| ERR-004 | 文件被占用 | 关闭占用程序后重试 |
| ERR-005 | 终端设置失败 | 检查注册表权限 |