From abc5ef4e408612d2e7657d78411609490cafb0b7 Mon Sep 17 00:00:00 2001 From: Cp0204 Date: Tue, 12 Nov 2024 11:39:22 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20=E6=B7=BB=E5=8A=A0=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E8=84=9A=E6=9C=AC=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 确保输出编码为utf-8,避免编码问题 --- app/run.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/run.py b/app/run.py index 968424e..427b37c 100644 --- a/app/run.py +++ b/app/run.py @@ -179,12 +179,18 @@ def run_script_now(): ) def generate_output(): + # 设置环境变量 + process_env = os.environ.copy() + process_env["PYTHONIOENCODING"] = "utf-8" process = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, + encoding="utf-8", + errors="replace", bufsize=1, + env=process_env, ) try: for line in iter(process.stdout.readline, ""):