From 1035b1291cfff67e6065f51410f6ca56406a8edd Mon Sep 17 00:00:00 2001 From: GoldenFish123321 Date: Wed, 3 Jun 2026 23:15:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Windows=20=E7=AE=A1?= =?UTF-8?q?=E9=81=93=20GBK=20=E7=BC=96=E7=A0=81=E5=AF=BC=E8=87=B4=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E6=96=87=E4=BB=B6=20UTF-8=20=E8=A7=A3=E7=A0=81?= =?UTF-8?q?=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit subprocess.Popen(text=True) 在 Windows 上默认使用系统编码(GBK)处理管道 IO, 导致 team_name 等中文字段被 GBK 编码后写入结果文件,Python 用 UTF-8 读取时崩溃。 改为显式 encoding=utf-8,与 pbb_all.cpp 全程 UTF-8 行为一致。 --- engine.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/engine.py b/engine.py index 48ab126..bc2346a 100644 --- a/engine.py +++ b/engine.py @@ -197,7 +197,8 @@ def run(config: dict, engine_bin: str = None, out_dir: str = None, t0 = time.time() proc = subprocess.Popen( [engine_bin], stdin=subprocess.PIPE, - stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, text=True) + stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, + encoding="utf-8", errors="replace") proc.stdin.write(params) proc.stdin.close() @@ -226,7 +227,7 @@ def run(config: dict, engine_bin: str = None, out_dir: str = None, mxp, mxd = 0, 0 result_path = os.path.join(result_dir, result_file) if os.path.exists(result_path): - with open(result_path, encoding="utf-8") as f: + with open(result_path, encoding="utf-8", errors="replace") as f: for line in f: line = line.strip() if not line: continue