From 40c197149ece2841660d6597a7229e893f3812b3 Mon Sep 17 00:00:00 2001 From: shy3130 Date: Mon, 13 Jul 2026 20:51:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(dev):=20dev.ps1=20Start-Job=20=E5=AD=90?= =?UTF-8?q?=E8=BF=9B=E7=A8=8B=E5=BC=BA=E5=88=B6=20UTF-8,=20=E4=BF=AE?= =?UTF-8?q?=E5=90=8E=E7=AB=AF=E4=B8=AD=E6=96=87=E6=97=A5=E5=BF=97=E4=B9=B1?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Start-Job 开的是全新 powershell.exe 子进程, 不继承主进程第 25-28 行 设的 UTF-8, 默认用系统 ANSI (中文 Windows = GBK/cp936) 解码后端的 UTF-8 输出 → 中文变 '瀹氫箟缂哄皯' 式乱码 (UTF-8 被当 GBK 解)。 第 25 行注释 'so child process logs aren't garbled' 的意图因 Start-Job 开新进程而落空。在 backend/frontend 两个 scriptBlock 开头各设 UTF-8, 与 app/__init__.py 的 stdout/stderr 编码对齐。 PowerShell 语法校验通过。 --- dev.ps1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dev.ps1 b/dev.ps1 index 730c95e..a89464f 100644 --- a/dev.ps1 +++ b/dev.ps1 @@ -171,6 +171,11 @@ $frontendPidFile = [System.IO.Path]::GetTempFileName() $backendJob = Start-Job -Name 'backend' -ScriptBlock { param($pidFile, $dir, $port) + # Start-Job 开的是全新 powershell.exe 子进程, 不继承主进程的 UTF-8 设置, + # 默认用系统 ANSI (中文 Windows = GBK/cp936) 解码后端 UTF-8 输出 → 中文乱码。 + # 这里强制子进程用 UTF-8, 与 app/__init__.py 的 stdout/stderr 编码对齐。 + [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding $false + $OutputEncoding = New-Object System.Text.UTF8Encoding $false $PID | Out-File -FilePath $pidFile -Encoding ascii -Force $env:PYTHONUNBUFFERED = '1' Set-Location $dir @@ -179,6 +184,9 @@ $backendJob = Start-Job -Name 'backend' -ScriptBlock { $frontendJob = Start-Job -Name 'frontend' -ScriptBlock { param($pidFile, $dir, $port) + # 同上: job 子进程默认 GBK, pnpm/前端工具链也是 UTF-8 输出, 需对齐。 + [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding $false + $OutputEncoding = New-Object System.Text.UTF8Encoding $false $PID | Out-File -FilePath $pidFile -Encoding ascii -Force Set-Location $dir & pnpm dev --host 0.0.0.0 --port $port 2>&1