From e6bcad86cb896564240f56b9dfdfc81821a81b48 Mon Sep 17 00:00:00 2001 From: Wanderingss <1624155937@qq.com> Date: Mon, 12 Oct 2026 13:21:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E7=9C=8B=E9=97=A8=E7=8B=97=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=BC=96=E7=A0=81=EF=BC=9A*>>=20=E5=9C=A8=20PS5.1=20?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=86=99=20UTF-16LE=EF=BC=8C=E6=B1=A1?= =?UTF-8?q?=E6=9F=93=E5=90=8C=E4=B8=80=E4=B8=AA=E6=97=A5=E5=BF=97=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现场(2026-10-12 注册计划任务后实测):runner-stdout.log 尾部按 UTF-8 读出来 是 "t i m e = 2 0 2 6 - 1 0 - 1 2 ...",即每个字节后面跟一个 NUL。 根因正是我自己刚写进文档的那条坑:PS 5.1 的 *>> 重定向由 Out-File 实现,而 Out-File 的默认编码是 UTF-16LE。同一个文件里 Log() 用 Add-Content -Encoding ascii 写 ASCII 行、daemon 输出却以 UTF-16LE 追加,于是"一个文件两种编码", 排障时按 UTF-8 读就是乱码——等于把唯一的 runner 现场日志弄成不可读。 - daemon 输出改到独立文件 runner-daemon.log,显式 Out-File -Encoding utf8 (不用 ascii:提交标题与作业输出可能含非 ASCII,ascii 会打成问号) - 看门狗自身日志改名 runner-watchdog.log,与 daemon 输出彻底分离 - 模板与生成物均校验通过:parseErrors=0、nonASCII=0 - 旧 runner-stdout.log 保留作历史,不再写入 --- scripts/ci_runner_bootstrap.ps1 | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/ci_runner_bootstrap.ps1 b/scripts/ci_runner_bootstrap.ps1 index fa469051..bd84d483 100644 --- a/scripts/ci_runner_bootstrap.ps1 +++ b/scripts/ci_runner_bootstrap.ps1 @@ -338,7 +338,8 @@ $runnerDir = '__RUNNER_DIR__' $runnerExe = Join-Path $runnerDir 'gitea-runner.exe' $runnerCfg = Join-Path $runnerDir 'config.yaml' $logDir = Join-Path $runnerDir 'log' -$log = Join-Path $logDir 'runner-stdout.log' +$log = Join-Path $logDir 'runner-watchdog.log' +$daemonLog = Join-Path $logDir 'runner-daemon.log' $probeUrl = '__GITEA_URL__/api/v1/version' $maxWaitSec = 1800 @@ -371,7 +372,15 @@ while ($true) { } Log 'starting daemon' - & $runnerExe daemon --config $runnerCfg *>> $log + # MEASURED TRAP (2026-10-12, hit by this very script): in PowerShell 5.1 the + # *>> redirection is implemented with Out-File, whose DEFAULT ENCODING IS + # UTF-16LE. Appending that into a file whose other lines come from + # Add-Content -Encoding ascii leaves ONE FILE WITH TWO ENCODINGS, and the + # daemon lines read back as "t i m e = 2 0 2 6 ..." (a NUL after every byte). + # Never rely on a redirection's default encoding -- state it explicitly. + # utf8 (not ascii) because job/commit text can legitimately be non-ASCII. + & $runnerExe daemon --config $runnerCfg 2>&1 | + Out-File -FilePath $daemonLog -Append -Encoding utf8 Log ("daemon exited, exit code {0}; restarting in 10s" -f $LASTEXITCODE) Start-Sleep -Seconds 10 } @@ -415,7 +424,8 @@ if ($StartNow) { Warn "Gitea is not answering at $GiteaUrl right now -- the watchdog will keep waiting" } Start-ScheduledTask -TaskName $TaskName - Ok "task started; watch: Get-Content '$(Join-Path $RunnerDir 'log\runner-stdout.log')' -Tail 20" + Ok "task started; daemon log: Get-Content '$(Join-Path $RunnerDir 'log\runner-daemon.log')' -Tail 20" + Ok "watchdog log: Get-Content '$(Join-Path $RunnerDir 'log\runner-watchdog.log')' -Tail 20" Info 'verify on the web UI: repo -> Settings -> Actions -> Runners -> win-stm32-ci should turn Idle' }