MikiVL 6b2c87dc18 修复 Windows 编码问题导致生成失败
Windows 默认编码为 GBK,Python stdout 输出含中文的 JSON 时
Node.js 端无法正确解析,导致批量生成操作静默失败。

- python/main.py:启动时强制 stdin/stdout 使用 UTF-8
- templateIpc.js:spawn 传入 PYTHONUTF8=1,改用 Buffer 拼接后 UTF-8 解码

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-07 11:41:55 +08:00

31 lines
970 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import sys
import json
import io
# Windows 默认编码不是 UTF-8强制设置
sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding="utf-8")
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", line_buffering=True)
def main():
for line in sys.stdin:
line = line.strip()
if not line:
continue
try:
req = json.loads(line)
action = req.get("action")
if action == "parse_template":
from xl_parser import parse_template
result = parse_template(req["file_path"])
elif action == "generate":
from generator import generate
result = generate(req)
else:
result = {"error": f"unknown action: {action}"}
except Exception as e:
result = {"error": str(e)}
print(json.dumps(result, ensure_ascii=False), flush=True)
if __name__ == "__main__":
main()