Windows Encoding Hardening

    by Smith John

    1

    Fix Windows mojibake in four layers: script BOM, console output, piped stdio, shell interop.

    $5

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Windows Encoding Hardening

    Example session with this skill installed

    我的 .ps1 里中文全是乱码,报「无效的值」,Python 也报 'gbk' codec can't encode character

    • Read your context and instructions
    • Compiled the windows encoding hardening

    先判层:.ps1 无 BOM + 中文 = 第 1 层 → 另存 UTF-8 带 BOM,路径改从 param() 传入;emoji 崩 GBK = 第 2 层 → 落文件或换 [FAIL] 标记。附录脚本一条命令取证。

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Windows 上中文变乱码,99% 不是「文件坏了」,而是某一层的默认编码不是 UTF-8。

    这个技能把问题分成四层,每层都给了症状、一步验证和修法:

    1. 脚本文件 — .ps1 无 BOM 会被按 GBK 解码,中文字面量变乱码、中文路径报「无效的值」
    2. 控制台输出 — 屏幕乱码但文件正常,先证明是显示坏不是文件坏
    3. 子进程管道 stdio — 重定向绕过 chcp 65001,中文变问号或抛编码异常
    4. shell 互操作 — Git-Bash/MSYS 改写传给 exe 的路径

    另外收了三个伪装成编码问题的坑:文本模式写坏二进制、Get-ChildItem -Recurse 超长路径静默少算、中文路径做进程签名匹配不到导致误判进程没在跑。

    文末附录带一个纯 ASCII 的取证脚本,一条命令打出 PowerShell 版本、ANSI/OEM 代码页、控制台编码、是否在 MSYS、每个文件的 BOM/UTF-8 合法性/非 ASCII 字节数、Python stdio 编码——第 1 层和第 3 层的问题一次定位。

    适合:在 Windows 上写脚本、跑 Python、调 CLI 的人(或让 AI 代跑这些活)。 不适合:Linux/容器里的 locale 问题——那是另一套(LANG/locale),本技能不管。

    只覆盖 Windows 上的编码问题:Linux / 容器里的 LANG、locale 不在范围内。PowerShell 7+ 默认 UTF-8,第 1 层(BOM)的规则对它用不上。技能不代跑程序,只给判层方法与取证脚本。

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Frequently Asked Questions

    只有判出是哪一层的默认值在起作用之后。先改代码是最常见的错误动作——多数情况是文件本身没问题,只是终端按 GBK 解码。

    不需要。PS 7+ 默认按 UTF-8 读,第 1 层规则对它不适用;但加了 BOM 也不会坏。

    不会。它只给判定方法和一个只读的取证脚本,所有改动都由你自己(或你的 agent)执行。

    重定向的 stdio 会绕过 chcp;而无条件把交互控制台改成 UTF-8 会让 GBK 环境下手打中文变乱码。这是技能里明确标注的过度修正。

    New in Testing & Debugging

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Testing & Debugging.