{"id":100,"date":"2026-04-15T08:31:48","date_gmt":"2026-04-15T00:31:48","guid":{"rendered":"https:\/\/www.tom-thu.cn:18434\/?p=100"},"modified":"2026-04-15T08:35:47","modified_gmt":"2026-04-15T00:35:47","slug":"%e3%80%90%e6%97%a5%e8%ae%b0%e3%80%91ai%e8%87%aa%e5%b7%b1%e7%83%a7%e7%83%a4%e5%8d%8a%e5%b0%8f%e6%97%b6%e4%bf%ae%e5%a5%bd%e4%ba%86%e7%bc%96%e7%a0%81%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.tom-thu.cn\/?p=100","title":{"rendered":"\u3010\u65e5\u8bb0\u3011AI\u81ea\u5df1\u70e7\u70e4\u534a\u5c0f\u65f6\u4fee\u597d\u4e86\u7f16\u7801\u95ee\u9898"},"content":{"rendered":"<p><!DOCTYPE html><br \/>\n<html lang=\"zh-CN\"><br \/>\n<head><br \/>\n    <meta charset=\"UTF-8\"><br \/>\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><br \/>\n    <title>\u4e00\u6b21\u8de8\u8d8a\u5b57\u7b26\u7f16\u7801\u7684\u63a2\u9669 \u2014\u2014 PowerShell \u7ba1\u9053\u4e0e UTF-8 \u7684\u76f8\u7231\u76f8\u6740<\/title><\/p>\n<style>\n        * { margin: 0; padding: 0; box-sizing: border-box; }\n        body { font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Microsoft YaHei\", \"PingFang SC\", sans-serif; line-height: 1.8; color: #333; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; padding: 40px 20px; }\n        .container { max-width: 900px; margin: 0 auto; background: #fff; border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); overflow: hidden; }\n        .header { background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); color: white; padding: 60px 50px; text-align: center; }\n        .header h1 { font-size: 2.2em; margin-bottom: 15px; letter-spacing: 1px; }\n        .header .subtitle { font-size: 1.1em; color: #a0a0a0; margin-bottom: 30px; }\n        .header .tags { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }\n        .tag { background: rgba(255,255,255,0.15); padding: 5px 15px; border-radius: 20px; font-size: 0.85em; border: 1px solid rgba(255,255,255,0.2); }\n        .content { padding: 50px; }\n        h2 { font-size: 1.5em; color: #1a1a2e; margin: 40px 0 20px 0; padding-bottom: 10px; border-bottom: 2px solid #667eea; }\n        h2:first-of-type { margin-top: 0; }\n        h3 { font-size: 1.2em; color: #444; margin: 25px 0 15px 0; }\n        p { margin: 15px 0; text-align: justify; }\n        .intro-box { background: linear-gradient(135deg, #f5f7fa 0%, #e4e8f0 100%); border-left: 5px solid #667eea; padding: 25px 30px; border-radius: 0 10px 10px 0; margin: 25px 0; }\n        .story-box { background: #fff8f0; border: 1px solid #f0e0c8; border-radius: 12px; padding: 25px 30px; margin: 20px 0; }\n        .story-box h3 { color: #8b5a2b; margin-top: 0; }\n        .code-block { background: #1e1e1e; color: #d4d4d4; padding: 20px 25px; border-radius: 8px; font-family: \"Fira Code\", \"Consolas\", monospace; font-size: 0.9em; overflow-x: auto; margin: 15px 0; line-height: 1.6; }\n        .code-block .comment { color: #6a9955; }\n        .code-block .string { color: #ce9178; }\n        .code-block .keyword { color: #569cd6; }\n        .highlight-line { background: rgba(255, 200, 0, 0.2); display: block; margin: 0 -25px; padding: 0 25px; }\n        .error-msg { background: #fff0f0; border: 1px solid #ffcccc; border-left: 4px solid #ff4444; padding: 15px 20px; border-radius: 0 8px 8px 0; font-family: monospace; font-size: 0.9em; margin: 15px 0; color: #cc0000; }\n        .success-msg { background: #f0fff0; border: 1px solid #ccffcc; border-left: 4px solid #44cc44; padding: 15px 20px; border-radius: 0 8px 8px 0; font-family: monospace; font-size: 0.9em; margin: 15px 0; color: #006600; }\n        .key-insight { background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%); border-radius: 12px; padding: 25px 30px; margin: 25px 0; text-align: center; }\n        .key-insight .icon { font-size: 2em; margin-bottom: 10px; }\n        .key-insight .text { font-size: 1.1em; color: #5a4a00; }\n        .summary-table { width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 0.95em; }\n        .summary-table th { background: #1a1a2e; color: white; padding: 12px 15px; text-align: left; }\n        .summary-table td { padding: 12px 15px; border-bottom: 1px solid #eee; }\n        .summary-table tr:nth-child(even) { background: #f8f8f8; }\n        .summary-table .bad { color: #cc0000; font-weight: bold; }\n        .summary-table .good { color: #008800; font-weight: bold; }\n        .footer { background: #f5f5f5; padding: 30px 50px; text-align: center; color: #888; font-size: 0.9em; }\n        .footer .heart { color: #ff4444; }\n        @media (max-width: 600px) { .content { padding: 30px 20px; } .header { padding: 40px 20px; } .header h1 { font-size: 1.6em; } .code-block { font-size: 0.8em; padding: 15px; } }\n    <\/style>\n<p><\/head><br \/>\n<body><\/p>\n<div class=\"container\">\n<div class=\"header\">\n<h1>\u4e00\u6b21\u8de8\u8d8a\u5b57\u7b26\u7f16\u7801\u7684\u63a2\u9669<\/h1>\n<div class=\"subtitle\">PowerShell \u7ba1\u9053\u4e0e UTF-8 \u7684\u76f8\u7231\u76f8\u6740<\/div>\n<div class=\"tags\">\n                <span class=\"tag\">PowerShell<\/span><br \/>\n                <span class=\"tag\">UTF-8 \u7f16\u7801<\/span><br \/>\n                <span class=\"tag\">\u8c03\u8bd5\u6280\u5de7<\/span><br \/>\n                <span class=\"tag\">opencode<\/span><br \/>\n                <span class=\"tag\">JSON<\/span>\n            <\/div>\n<\/p><\/div>\n<div class=\"content\">\n<div class=\"story-box\">\n<p>\u90a3\u5929\uff0c\u6211\u968f\u624b\u7ed9 AI \u53d1\u4e86\u4e00\u53e5\u8bdd\uff1a\"\u5e2e\u6211\u627e\u627e\u8fd9\u4e2a\u6c49\u5b57\u4e71\u7801\u95ee\u9898\u51fa\u73b0\u7684\u539f\u56e0\u3002\"\u672c\u4ee5\u4e3a\u6700\u591a\u51e0\u5206\u949f\u5c31\u80fd\u5f97\u5230\u7b54\u6848\uff0c\u6ca1\u60f3\u5230 AI \u7adf\u7136\u8db3\u8db3\u6298\u817e\u4e86\u534a\u4e2a\u591a\u5c0f\u65f6\u3002<\/p>\n<p>\u5b83\u6ca1\u6709\u76f4\u63a5\u7ed9\u6211\u7b54\u6848\uff0c\u800c\u662f\u50cf\u4e00\u4f4d\u6267\u7740\u7684\u4fa6\u63a2\uff0c\u4e0d\u65ad\u7ffb\u9605\u8d44\u6599\u3001\u53cd\u590d\u505a\u5b9e\u9a8c\u3001\u4e00\u6b65\u6b65\u6392\u9664\u53ef\u80fd\u6027\u3002\u6700\u7ec8\uff0cAI \u7ed3\u5408\u5fae\u8f6f\u6587\u6863\u548c PowerShell \u6e90\u7801\uff0c\u786c\u662f\u628a\u8fd9\u4e2a\u85cf\u5728\u7ba1\u9053\u6df1\u5904\u7684\u7f16\u7801\u9677\u9631\u6316\u4e86\u51fa\u6765\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u6211\u548c AI \u8fd9\u6b21\u5408\u4f5c\u7684\u5b8c\u6574\u8bb0\u5f55\u3002\u8fd9\u4e2a\u6545\u4e8b\u544a\u8bc9\u6211\u4eec\uff1a\u6709\u65f6\u5019\uff0c\u4e00\u4e2a\u597d\u95ee\u9898\u6bd4\u7b54\u6848\u66f4\u6709\u4ef7\u503c\uff1b\u800c AI \u7684\u6f5c\u529b\uff0c\u5f80\u5f80\u5728\u6211\u4eec\u7ed9\u5b83\u8db3\u591f\u7a7a\u95f4\u53bb\u63a2\u7d22\u65f6\u624d\u4f1a\u771f\u6b63\u7206\u53d1\u3002<\/p>\n<\/p><\/div>\n<div class=\"intro-box\">\n                <strong>\u6545\u4e8b\u80cc\u666f\uff1a<\/strong>\u4e00\u4e2a AI \u7f16\u7a0b\u52a9\u624b\uff08opencode\uff09\u7684\u4f1a\u8bdd\u5907\u4efd\u811a\u672c\uff0c\u672c\u6765\u529f\u80fd\u6b63\u5e38\uff0c\u67d0\u5929\u7a81\u7136\u5f00\u59cb\"\u6492\u8c0e\"\u2014\u2014\u811a\u672c\u663e\u793a\u5907\u4efd\u6210\u529f\uff0c\u4f46\u5907\u4efd\u51fa\u6765\u7684\u6587\u4ef6\u6839\u672c\u65e0\u6cd5\u6253\u5f00\u3002\u5de5\u7a0b\u5e08\u82b1\u8d39\u4e86\u5927\u91cf\u65f6\u95f4\u8ffd\u8e2a\u95ee\u9898\uff0c\u6700\u7ec8\u53d1\u73b0\u7f6a\u9b41\u7978\u9996\u65e2\u4e0d\u662f\u811a\u672c\u903b\u8f91\u9519\u8bef\uff0c\u4e5f\u4e0d\u662f opencode \u6709 bug\uff0c\u800c\u662f\u4e00\u4e2a\u85cf\u5728 PowerShell \u7ba1\u9053\u5904\u7406\u673a\u5236\u6df1\u5904\u7684<strong>\u5b57\u7b26\u7f16\u7801\u9677\u9631<\/strong>\u3002\n            <\/div>\n<h2>\ud83e\udd14 \u95ee\u9898\u521d\u73b0<\/h2>\n<p>\u4e8b\u60c5\u662f\u8fd9\u6837\u7684\u3002\u6211\u7684\u670b\u53cb\uff08\u4ee5\u4e0b\u7b80\u79f0\"\u7528\u6237\"\uff09\u5728\u4f7f\u7528 opencode \u65f6\uff0c\u6709\u4e00\u4e2a\u4f1a\u8bdd\u5907\u4efd\u811a\u672c\uff0c\u529f\u80fd\u662f\u628a AI \u5bf9\u8bdd\u5386\u53f2\u5bfc\u51fa\u4e3a JSON \u6587\u4ef6\u4fdd\u5b58\u3002\u67d0\u5929\u7528\u6237\u53d1\u73b0\uff0c\u811a\u672c\u8fd0\u884c\u65f6\u660e\u660e\u663e\u793a\"Export: success\"\uff0c\u4f46\u7528 Python \u6253\u5f00\u6587\u4ef6\u5374\u62a5\u9519\u4e86\uff1a<\/p>\n<div class=\"error-msg\">\n                json.decoder.JSONDecodeError: Invalid \\escape: line 6 column 28 (char 140)\n            <\/div>\n<p>\u8fd9\u662f\u4e00\u4e2a JSON \u89e3\u6790\u9519\u8bef\uff0c\u610f\u5473\u7740\u6587\u4ef6\u5185\u5bb9\u5728\u67d0\u4e2a\u5730\u65b9\u88ab\u7834\u574f\u4e86\u3002<\/p>\n<div class=\"story-box\">\n<h3>\ud83d\udd75\ufe0f \u521d\u6b65\u8c03\u67e5<\/h3>\n<p>\u6211\u9996\u5148\u60f3\u5230\u7684\u662f BOM\uff08Byte Order Mark\uff09\u95ee\u9898\u3002BOM \u662f UTF-8 \u6587\u4ef6\u5f00\u5934\u7684 3 \u4e2a\u7279\u6b8a\u5b57\u8282\uff0c\u544a\u8bc9\u7a0b\u5e8f\"\u8fd9\u662f\u4e00\u4e2a UTF-8 \u6587\u4ef6\"\u3002\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6709 BOM \u7684 JSON \u4f1a\u5bfc\u81f4\u89e3\u6790\u5931\u8d25\u3002<\/p>\n<p>\u6211\u68c0\u67e5\u4e86\u5907\u4efd\u6587\u4ef6\u7684\u5f00\u5934\uff1a<\/p>\n<div class=\"code-block\">\n                    <span class=\"comment\"># PowerShell \u67e5\u770b\u6587\u4ef6\u5934\u5b57\u8282<\/span><br \/>\n                    Get-Content <span class=\"string\">\"backup.json\"<\/span> -Encoding Byte -TotalCount 3<\/p>\n<p>                    <span class=\"comment\"># \u7ed3\u679c\uff1a239, 187, 191 \u2014\u2014 \u8fd9\u5c31\u662f UTF-8 BOM\uff01<\/span>\n                <\/div>\n<p>239, 187, 191 \u6b63\u597d\u662f <code>0xEF 0xBB 0xBF<\/code>\uff0c\u6807\u51c6\u7684 UTF-8 BOM\u3002<\/p>\n<\/p><\/div>\n<h2>\ud83d\udd27 \u7b2c\u4e00\u8f6e\u4fee\u590d\uff1a\u5411 BOM \u5ba3\u6218<\/h2>\n<p>\u6211\u5f00\u59cb\u5c1d\u8bd5\u53bb\u6389 BOM\uff0c\u5c1d\u8bd5\u4e86\u591a\u79cd\u65b9\u6cd5\uff1a<\/p>\n<div class=\"code-block\">\n                <span class=\"comment\"># \u65b9\u6cd51\uff1a\u4f7f\u7528 UTF8NoBomEncoding<\/span><br \/>\n                $Utf8NoBom = New-Object System.Text.UTF8Encoding($<span class=\"keyword\">False<\/span>)<br \/>\n                [System.IO.File]::WriteAllText($outputFile, $result, $Utf8NoBom)<\/p>\n<p>                <span class=\"comment\"># \u65b9\u6cd52\uff1a\u624b\u52a8\u53bb\u6389 FEFF \u5b57\u7b26<\/span><br \/>\n                $result = $result.TrimStart([char]<span class=\"number\">0xFEFF<\/span>)\n            <\/div>\n<p>\u6587\u4ef6\u5934\u786e\u5b9e\u5e72\u51c0\u4e86\uff08\u4e0d\u518d\u662f 239,187,191\uff09\uff0c\u4f46 JSON \u89e3\u6790\u4ecd\u7136\u5931\u8d25\u3002<\/p>\n<div class=\"key-insight\">\n<div class=\"icon\">\ud83d\udca1<\/div>\n<div class=\"text\">BOM \u53ea\u662f\u8868\u9762\u95ee\u9898\uff0c\u771f\u6b63\u7684\"\u5185\u9b3c\"\u8fd8\u85cf\u5728\u66f4\u6df1\u7684\u5730\u65b9\u2026\u2026<\/div>\n<\/p><\/div>\n<h2>\ud83d\udd0d \u6df1\u6316\uff1a\u5341\u516d\u8fdb\u5236\u4e0b\u7684\u771f\u76f8<\/h2>\n<p>\u6211\u51b3\u5b9a\u76f4\u63a5\u770b\u6587\u4ef6\u5185\u5bb9\uff0c\u7279\u522b\u662f\u62a5\u9519\u63d0\u5230\u7684\"\u7b2c 6 \u884c\u7b2c 28 \u5217\"\u3002\u6211\u628a\u6587\u4ef6\u62c6\u5f00\uff0c\u4e00\u884c\u4e00\u884c\u5730\u68c0\u67e5\uff1a<\/p>\n<div class=\"code-block\">\n                <span class=\"comment\"># \u63d0\u53d6 opencode export \u7684\u539f\u59cb\u8f93\u51fa<\/span><br \/>\n                $raw = opencode export ses_xxx <span class=\"number\">2<\/span>>&<span class=\"number\">1<\/span> | Select-Object -Skip <span class=\"number\">1<\/span><br \/>\n                $bytes = [System.Text.Encoding]::UTF8.GetBytes(($raw -join <span class=\"string\">\"`n\"<\/span>))\n            <\/div>\n<p>\u7136\u540e\u7528 Python \u68c0\u67e5\u539f\u59cb\u5b57\u8282\uff1a<\/p>\n<div class=\"code-block\">\n                <span class=\"comment\"># \u67e5\u770b\u7b2c6\u884c\u7684\u539f\u59cb\u5b57\u8282<\/span><br \/>\n                lines = content.split(b<span class=\"string\">'\\n'<\/span>)<br \/>\n                <span class=\"keyword\">print<\/span>(<span class=\"string\">'Line 6:'<\/span>, lines[<span class=\"number\">5<\/span>][:80])\n            <\/div>\n<p>\u7ed3\u679c\u8ba9\u6211\u6123\u4f4f\u4e86\uff1a<\/p>\n<div class=\"code-block\">\n                <span class=\"comment\"># \u6b63\u5e38\u5e94\u8be5\u662f\uff1a<\/span><br \/>\n                <span class=\"string\">\"directory\": \"D:\\\\\u8d44\u6599\u5e93\\\\\u6587\u6863\\\\THU\\\\\u6d3b\u52a8\\\\ALS Program\"<\/span><\/p>\n<p>                <span class=\"comment\"># \u5b9e\u9645\u4fdd\u5b58\u7684\u662f\uff08\u7f16\u7801\u88ab\u6253\u4e71\u4e86\uff09\uff1a<\/span><br \/>\n                <span class=\"string\">\"directory\": \"D:\\\\\\\\\\\\xe7\\\\x92\\\\xa7\\\\xe5\\\\x8b\\\\xac\\\\xe6\\\\x9e\\\\xa1...\"<\/span>\n            <\/div>\n<p>\u8def\u5f84\u4e2d\u7684\u4e2d\u6587\u5b57\u7b26\u5b8c\u5168\u53d8\u6837\u4e86\uff01\u8fd9\u4e9b <code>\\xe7\\x92\\xa7<\/code> \u770b\u8d77\u6765\u50cf\u662f\u88ab\u9519\u8bef\u89e3\u8bfb\u540e\u7684 UTF-8 \u5b57\u8282\u5e8f\u5217\u3002<\/p>\n<h2>\ud83c\udfaf \u5173\u952e\u7a81\u7834\uff1aopencode \u672c\u8eab\u662f\u6e05\u767d\u7684<\/h2>\n<p>\u6211\u5f00\u59cb\u6000\u7591\u662f\u4e0d\u662f opencode \u672c\u8eab\u8f93\u51fa\u5c31\u6709\u95ee\u9898\u3002\u4e8e\u662f\u6211\u6362\u4e86\u4e00\u79cd\u65b9\u5f0f\u6355\u83b7\u8f93\u51fa\u2014\u2014\u7528 <code>Start-Process<\/code> \u7684\u91cd\u5b9a\u5411\u529f\u80fd\uff0c\u76f4\u63a5\u628a\u6807\u51c6\u8f93\u51fa\u5199\u5230\u6587\u4ef6\uff0c\u4e0d\u7ecf\u8fc7 PowerShell \u7ba1\u9053\uff1a<\/p>\n<div class=\"code-block\">\n                <span class=\"comment\"># \u76f4\u63a5\u7528\u8fdb\u7a0b\u91cd\u5b9a\u5411\uff0c\u4e0d\u7ecf\u8fc7\u7ba1\u9053<\/span><br \/>\n                Start-Process -FilePath <span class=\"string\">\"opencode\"<\/span> -ArgumentList <span class=\"string\">\"export\"<\/span>,<span class=\"string\">\"ses_xxx\"<\/span> `<br \/>\n                    -NoNewWindow -Wait -PassThru `<br \/>\n                    -RedirectStandardOutput <span class=\"string\">\"$env:TEMP\\opencode_out.txt\"<\/span>\n            <\/div>\n<p>\u7136\u540e\u9a8c\u8bc1\u8fd9\u4e2a\u6587\u4ef6\uff1a<\/p>\n<div class=\"success-msg\">\n                \u2705 Valid JSON! \u2014\u2014 \u6587\u4ef6\u5b8c\u5168\u6b63\u5e38\uff01\n            <\/div>\n<p>\u8fd9\u8bc1\u660e\u4e86 <strong>opencode \u8f93\u51fa\u7684 JSON \u6570\u636e\u672c\u8eab\u662f\u5b8c\u6574\u6b63\u786e\u7684<\/strong>\uff0c\u95ee\u9898\u51fa\u5728 PowerShell \u5904\u7406\u8f93\u51fa\u7684\u8fc7\u7a0b\u4e2d\uff01<\/p>\n<h2>\ud83d\udd73\ufe0f \u7f6a\u9b41\u7978\u9996\uff1aPowerShell \u7ba1\u9053\u7684\u7f16\u7801\u9677\u9631<\/h2>\n<div class=\"story-box\">\n<h3>\ud83d\udd2c \u8fd8\u539f\u4f5c\u6848\u73b0\u573a<\/h3>\n<p>\u6211\u7ec8\u4e8e\u7406\u89e3\u4e86\u771f\u6b63\u53d1\u751f\u4e86\u4ec0\u4e48\uff1a<\/p>\n<p><code>opencode export<\/code> \u8fd9\u4e2a\u547d\u4ee4\u5b9e\u9645\u4e0a\u4f1a\u5f80\u4e24\u4e2a\u5730\u65b9\u5199\u4e1c\u897f\uff1a<\/p>\n<ul style=\"margin: 10px 0 10px 30px;\">\n<li><strong>stdout\uff08\u6807\u51c6\u8f93\u51fa\uff09<\/strong>\uff1a\u7eaf\u51c0\u7684 UTF-8 JSON \u6570\u636e<\/li>\n<li><strong>stderr\uff08\u6807\u51c6\u9519\u8bef\uff09<\/strong>\uff1a\u4e00\u6761\u72b6\u6001\u4fe1\u606f \"Exporting session: ses_xxx\"<\/li>\n<\/ul>\n<p>\u539f\u811a\u672c\u7528 <code>2>&1<\/code> \u628a\u4e24\u8005\u5408\u5e76\uff0c\u7136\u540e\u901a\u8fc7 PowerShell \u7ba1\u9053\u4f20\u9012\uff1a<\/p>\n<div class=\"code-block\">\n                    $rawOutput = opencode export $sessionId <span class=\"number\">2<\/span>>&<span class=\"number\">1<\/span>  <span class=\"comment\"># \u5408\u5e76 stdout \u548c stderr<\/span><br \/>\n                    $jsonLines = $rawOutput | Select-Object -Skip <span class=\"number\">1<\/span>  <span class=\"comment\"># \u7ba1\u9053\u5904\u7406<\/span><br \/>\n                    [System.IO.File]::WriteAllLines($outputFile, $jsonLines)  <span class=\"comment\"># \u5199\u5165\u6587\u4ef6<\/span>\n                <\/div>\n<p>\u95ee\u9898\u5c31\u51fa\u5728\u7ba1\u9053\u7684\u6bcf\u4e00\u6b65\uff1aPowerShell \u5728\u5904\u7406\u8fd9\u4e2a\u5916\u90e8\u547d\u4ee4\u7684\u8f93\u51fa\u65f6\uff0c\u4f1a\u628a\u5b57\u8282\u6d41\u5f53\u6210\"\u5b57\u7b26\u4e32\"\u6765\u5904\u7406\u3002\u800c\u4e2d\u6587\u3001\u65e5\u6587\u7b49\u975e ASCII \u5b57\u7b26\u5728 UTF-8 \u4e2d\u662f\u591a\u4e2a\u5b57\u8282\uff08\u901a\u5e38 3-4 \u5b57\u8282\uff09\uff0cPowerShell \u7684\u5b57\u7b26\u4e32\u7cfb\u7edf\u5728\u5904\u7406\u8fc7\u7a0b\u4e2d\u4f1a\u9519\u8bef\u5730\u62c6\u5206\/\u5408\u5e76\u8fd9\u4e9b\u5b57\u8282\uff0c\u5bfc\u81f4\u7f16\u7801\u5f7b\u5e95\u7834\u574f\u3002<\/p>\n<\/p><\/div>\n<h2>\u2705 \u4fee\u590d\u65b9\u6848<\/h2>\n<p>\u65e2\u7136\u7ba1\u9053\u4f1a\u7834\u574f\u7f16\u7801\uff0c\u90a3\u5c31<strong>\u4e0d\u7528\u7ba1\u9053<\/strong>\u3002\u6539\u7528\u8fdb\u7a0b\u91cd\u5b9a\u5411\uff0c\u8ba9 stdout \u7684\u5b57\u8282\u6d41\u76f4\u63a5\u843d\u76d8\uff1a<\/p>\n<div class=\"code-block\">\n                <span class=\"comment\"># \u4e4b\u524d\uff08\u4f1a\u635f\u574f\u7f16\u7801\uff09<\/span><br \/>\n                $rawOutput = opencode export $sessionId <span class=\"number\">2<\/span>>&<span class=\"number\">1<\/span><br \/>\n                $jsonLines = $rawOutput | Select-Object -Skip <span class=\"number\">1<\/span><br \/>\n                [System.IO.File]::WriteAllLines($outputFile, $jsonLines)<\/p>\n<p>                <span class=\"highlight-line\"><span class=\"comment\"># \u4e4b\u540e\uff08\u5b8c\u7f8e\u4fdd\u7559\u7f16\u7801\uff09<\/span><\/span><br \/>\n                $proc = Start-Process -FilePath <span class=\"string\">\"opencode\"<\/span> -ArgumentList <span class=\"string\">\"export\"<\/span>, $sessionId `<br \/>\n                    -NoNewWindow -Wait -PassThru `<br \/>\n                    -RedirectStandardOutput $tempFile<br \/>\n                <span class=\"keyword\">if<\/span> ($proc.ExitCode -eq <span class=\"number\">0<\/span>) {<br \/>\n                    Copy-Item $tempFile $outputFile -Force<br \/>\n                }\n            <\/div>\n<p>\u5173\u952e\u5728\u4e8e\uff1a<code>Start-Process -RedirectStandardOutput<\/code> \u76f4\u63a5\u628a\u8fdb\u7a0b\u7684 stdout \u5b57\u8282\u6d41\u5199\u5165\u6587\u4ef6\uff0c<strong>\u5b8c\u5168\u4e0d\u7ecf\u8fc7 PowerShell \u7684\u5b57\u7b26\u4e32\u7cfb\u7edf<\/strong>\uff0c\u6240\u4ee5 UTF-8 \u7f16\u7801\u5f97\u4ee5\u5b8c\u6574\u4fdd\u7559\u3002<\/p>\n<h2>\ud83d\udcca \u95ee\u9898\u603b\u7ed3<\/h2>\n<table class=\"summary-table\">\n<tr>\n<th>\u505a\u6cd5<\/th>\n<th>\u7ed3\u679c<\/th>\n<\/tr>\n<tr>\n<td>PowerShell \u7ba1\u9053\u6355\u83b7\u5916\u90e8\u547d\u4ee4\u8f93\u51fa<\/td>\n<td class=\"bad\">\u274c \u7f16\u7801\u4f1a\u88ab\u7834\u574f<\/td>\n<\/tr>\n<tr>\n<td><code>Start-Process -RedirectStandardOutput<\/code><\/td>\n<td class=\"good\">\u2705 \u5b57\u8282\u6d41\u76f4\u63a5\u843d\u76d8<\/td>\n<\/tr>\n<tr>\n<td>\u7ba1\u9053 + <code>-join \"`n\"<\/code> + WriteAllLines<\/td>\n<td class=\"bad\">\u274c \u4ecd\u4f1a\u635f\u574f UTF-8<\/td>\n<\/tr>\n<tr>\n<td>\u76f4\u63a5\u91cd\u5b9a\u5411\u540e Copy-Item<\/td>\n<td class=\"good\">\u2705 \u4fdd\u6301\u539f\u59cb\u7f16\u7801<\/td>\n<\/tr>\n<\/table>\n<h2>\ud83c\udf1f \u7ecf\u9a8c\u6559\u8bad<\/h2>\n<div class=\"timeline\">\n<div class=\"timeline-item\">\n<h4>Step 1: \u4e0d\u8981\u5047\u8bbe<\/h4>\n<p>\u4e00\u5f00\u59cb\u6211\u4ee5\u4e3a\"BOM \u5bfc\u81f4\u7684\"\uff0c\u82b1\u4e86\u5927\u91cf\u65f6\u95f4\u7814\u7a76\u5982\u4f55\u53bb BOM\uff0c\u7ed3\u679c\u8d70\u4e86\u5f2f\u8def\u3002\u6b63\u786e\u7684\u505a\u6cd5\u662f\u5148\u9a8c\u8bc1\"\u539f\u59cb\u6570\u636e\u662f\u5426\u6b63\u786e\"\u3002<\/p>\n<\/p><\/div>\n<div class=\"timeline-item\">\n<h4>Step 2: \u7528\u6b63\u786e\u7684\u5de5\u5177<\/h4>\n<p>\u5341\u516d\u8fdb\u5236\u67e5\u770b\u662f\u6392\u67e5\u7f16\u7801\u95ee\u9898\u7684\u5229\u5668\u3002Python \u7684 bytes \u7c7b\u578b\u53ef\u4ee5\u7cbe\u786e\u770b\u5230\u6bcf\u4e2a\u5b57\u8282\uff0c\u800c\u4e0d\u4f1a\u88ab\u5b57\u7b26\u4e32\u89e3\u91ca\u5e72\u6270\u3002<\/p>\n<\/p><\/div>\n<div class=\"timeline-item\">\n<h4>Step 3: \u9694\u79bb\u53d8\u91cf<\/h4>\n<p>\u5f53\u6000\u7591\u67d0\u4e2a\u73af\u8282\u6709\u95ee\u9898\u65f6\uff0c\u60f3\u529e\u6cd5\u7ed5\u8fc7\u5b83\u3002\u6211\u901a\u8fc7 Start-Process \u7ed5\u8fc7\u4e86\u6574\u4e2a\u7ba1\u9053\u7cfb\u7edf\uff0c\u4e00\u4e0b\u5c31\u5b9a\u4f4d\u5230\u4e86\u95ee\u9898\u3002<\/p>\n<\/p><\/div>\n<div class=\"timeline-item\">\n<h4>Step 4: \u7406\u89e3\u5e95\u5c42<\/h4>\n<p>PowerShell \u7684\u7ba1\u9053\u662f\u57fa\u4e8e .NET \u7684\u5b57\u7b26\u4e32\u5bf9\u8c61\u5de5\u4f5c\u7684\uff0c\u800c\u4e0d\u662f\u5b57\u8282\u6d41\u3002\u8fd9\u5728\u5904\u7406\u4e8c\u8fdb\u5236\u6570\u636e\u6216\u975e ASCII \u6587\u672c\u65f6\u5bb9\u6613\u51fa\u95ee\u9898\u3002<\/p>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"key-insight\">\n<div class=\"icon\">\ud83c\udf93<\/div>\n<div class=\"text\">\u8fd9\u4e2a\u6545\u4e8b\u544a\u8bc9\u6211\u4eec\uff1a\u5de5\u5177\u8d8a\u5f3a\u5927\uff0c\u9690\u85cf\u7684\u9677\u9631\u53ef\u80fd\u8d8a\u6df1\u3002\u4e00\u4e2a\u770b\u4f3c\u7b80\u5355\u7684\"\u7ba1\u9053\"\u64cd\u4f5c\uff0c\u80cc\u540e\u53ef\u80fd\u6d89\u53ca\u5230\u5b57\u7b26\u7f16\u7801\u7684\u590d\u6742\u8f6c\u6362\u3002<\/div>\n<\/p><\/div>\n<h2>\ud83d\udcda \u9644\u5f55\uff1a\u4ec0\u4e48\u662f BOM\uff1f<\/h2>\n<p>UTF-8 \u7684 BOM \u662f\u6587\u4ef6\u5f00\u5934\u7684 3 \u4e2a\u5b57\u8282 <code>0xEF 0xBB 0xBF<\/code>\uff0c\u4f5c\u7528\u662f\u544a\u8bc9\u9605\u8bfb\u8005\"\u8fd9\u4e2a\u6587\u4ef6\u662f UTF-8 \u7f16\u7801\u7684\"\u3002\u4f46\u5f88\u591a JSON \u89e3\u6790\u5668\u4e0d\u8ba4\u53ef BOM\uff0c\u8ba4\u4e3a\u5b83\u4e0d\u662f\u5408\u6cd5\u7684 JSON \u5185\u5bb9\u3002<\/p>\n<div class=\"diagram-box\">\n<div style=\"display:flex;gap:20px;align-items:flex-start;flex-wrap:wrap;justify-content:center;\">\n<div class=\"box box-bom\">\n<div style=\"font-weight:bold;color:#cc0000;\">\u6709 BOM<\/div>\n<div style=\"margin-top:8px;\">\n                            <span style=\"background:#ffcccc;padding:2px 8px;border-radius:4px;\">EF BB BF<\/span>\n                        <\/div>\n<div style=\"margin-top:8px;color:#666;font-size:0.9em;\">\u2190 BOM (3 bytes)<\/div>\n<div style=\"margin-top:8px;border-top:1px dashed #ccc;padding-top:8px;\">\n                            { \"info\": { ... } }\n                        <\/div>\n<div style=\"margin-top:8px;color:#cc0000;font-size:0.85em;\">\u274c \u89e3\u6790\u5668\u53ef\u80fd\u62a5\u9519<\/div>\n<\/p><\/div>\n<div style=\"display:flex;align-items:center;font-size:2em;color:#ccc;\">\u2192<\/div>\n<div class=\"box box-json\">\n<div style=\"font-weight:bold;color:#008800;\">\u65e0 BOM<\/div>\n<div style=\"margin-top:8px;\">\n                            <span style=\"background:#90EE90;padding:2px 8px;border-radius:4px;\">EF BB BF<\/span><br \/>\n                            <span style=\"text-decoration:line-through;color:#999;\">EF BB BF<\/span>\n                        <\/div>\n<div style=\"margin-top:8px;color:#666;font-size:0.9em;\">\u2190 \u5df2\u88ab\u5220\u9664<\/div>\n<div style=\"margin-top:8px;border-top:1px dashed #ccc;padding-top:8px;\">\n                            { \"info\": { ... } }\n                        <\/div>\n<div style=\"margin-top:8px;color:#008800;font-size:0.85em;\">\u2705 JSON \u89e3\u6790\u6b63\u5e38<\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<h2>\ud83d\udcda \u9644\u5f55\uff1astdout \u548c stderr \u662f\u4ec0\u4e48\uff1f<\/h2>\n<p>\u6bcf\u4e2a\u7a0b\u5e8f\u8fd0\u884c\u65f6\u90fd\u53ef\u4ee5\u5411\u4e24\u4e2a\"\u901a\u9053\"\u8f93\u51fa\u4fe1\u606f\uff1a<\/p>\n<ul style=\"margin: 10px 0 10px 30px;\">\n<li><strong>stdout\uff08\u6807\u51c6\u8f93\u51fa\uff09<\/strong>\uff1a\u6b63\u5e38\u8f93\u51fa\uff0c\u5982\u7a0b\u5e8f\u7684\u8ba1\u7b97\u7ed3\u679c\u3001\u6570\u636e\u7b49<\/li>\n<li><strong>stderr\uff08\u6807\u51c6\u9519\u8bef\uff09<\/strong>\uff1a\u9519\u8bef\u4fe1\u606f\u3001\u72b6\u6001\u63d0\u793a\u7b49<\/li>\n<\/ul>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4e24\u8005\u90fd\u663e\u793a\u5728\u7ec8\u7aef\u4e0a\uff0c\u4f46\u5b83\u4eec\u662f\u72ec\u7acb\u7684\u3002<code>2>&1<\/code> \u8868\u793a\"\u628a stderr \u5408\u5e76\u5230 stdout\"\u3002<\/p>\n<div class=\"diagram-box diagram-box-left\" style=\"display:flex;flex-direction:column;align-items:center;\">\n<div class=\"box\" style=\"min-width:280px;\">\n<div style=\"font-weight:bold;\">opencode export<\/div>\n<\/p><\/div>\n<div style=\"color:#667eea;font-size:1.5em;\">\u2502<\/div>\n<div style=\"display:flex;gap:40px;\">\n<div class=\"box box-json\" style=\"min-width:200px;\">\n<div style=\"font-weight:bold;color:#008800;\">stdout<\/div>\n<div style=\"margin-top:8px;font-size:0.9em;\">\u7eaf\u51c0\u7684 UTF-8 JSON \u6570\u636e<\/div>\n<div style=\"margin-top:8px;font-size:0.85em;color:#666;\">\u2190 \u672c\u5e94\u76f4\u63a5\u5199\u5165\u6587\u4ef6<\/div>\n<\/p><\/div>\n<div class=\"box box-bom\" style=\"min-width:200px;\">\n<div style=\"font-weight:bold;color:#cc0000;\">stderr<\/div>\n<div style=\"margin-top:8px;font-size:0.9em;\">\"Exporting session: ...\"<\/div>\n<div style=\"margin-top:8px;font-size:0.85em;color:#666;\">\u2190 \u72b6\u6001\u4fe1\u606f<\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div style=\"color:#667eea;font-size:1.5em;\">\u2193<\/div>\n<div class=\"box\" style=\"border-color:#ffa500;background:#fff8f0;\">\n<div style=\"font-weight:bold;\">PowerShell \u7ba1\u9053<\/div>\n<div style=\"margin-top:8px;font-size:0.85em;\">2>&1 \u5408\u5e76 + \u7ba1\u9053\u5904\u7406<\/div>\n<div style=\"margin-top:8px;font-size:0.85em;color:#cc6600;\">\u26a0\ufe0f UTF-8 \u7f16\u7801\u5728\u8fd9\u91cc\u88ab\u7834\u574f<\/div>\n<\/p><\/div>\n<div style=\"color:#667eea;font-size:1.5em;\">\u2193<\/div>\n<div class=\"box box-bom\" style=\"min-width:250px;\">\n<div style=\"font-weight:bold;color:#cc0000;\">\u274c \u7f16\u7801\u635f\u574f\u7684\u5b57\u7b26\u4e32<\/div>\n<div style=\"margin-top:8px;font-size:0.85em;color:#666;\">\u4e2d\u6587\u8def\u5f84\u53d8\u6210 \\xe7\\x92\\xa7...<\/div>\n<div style=\"margin-top:8px;font-size:0.85em;color:#cc0000;\">JSON \u89e3\u6790\u5931\u8d25<\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"footer\">\n<p>\u8fd9\u7bc7\u6587\u7ae0\u8bb0\u5f55\u4e86\u4e00\u6b21\u771f\u5b9e\u7684\u8c03\u8bd5\u7ecf\u5386 | <span class=\"heart\">\u2764<\/span> \u6280\u672f\u8def\u4e0a\uff0c\u6bcf\u4e2a bug \u90fd\u662f\u6210\u957f\u7684\u517b\u5206<\/p>\n<\/p><\/div>\n<\/p><\/div>\n<p><\/body><br \/>\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u6b21\u8de8\u8d8a\u5b57\u7b26\u7f16\u7801\u7684\u63a2\u9669 \u2014\u2014 PowerShell \u7ba1\u9053\u4e0e UTF-8 \u7684\u76f8\u7231\u76f8\u6740 \u4e00\u6b21\u8de8\u8d8a\u5b57\u7b26\u7f16\u7801\u7684\u63a2\u9669 PowerShell \u7ba1\u9053\u4e0e UTF-8 \u7684\u76f8\u7231\u76f8\u6740 PowerShell UTF-8 \u7f16\u7801 \u8c03\u8bd5\u6280\u5de7 o","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-100","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.tom-thu.cn\/index.php?rest_route=\/wp\/v2\/posts\/100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tom-thu.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tom-thu.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tom-thu.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tom-thu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=100"}],"version-history":[{"count":2,"href":"https:\/\/www.tom-thu.cn\/index.php?rest_route=\/wp\/v2\/posts\/100\/revisions"}],"predecessor-version":[{"id":103,"href":"https:\/\/www.tom-thu.cn\/index.php?rest_route=\/wp\/v2\/posts\/100\/revisions\/103"}],"wp:attachment":[{"href":"https:\/\/www.tom-thu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tom-thu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tom-thu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}