From 6345c23f1f72d822361904fe4e95efa6c0820115 Mon Sep 17 00:00:00 2001 From: Zhengen TANG Date: Fri, 11 Sep 2026 13:54:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20install-nssm-services.ps1?= =?UTF-8?q?=EF=BC=9APS7=20=E4=B8=8B=E9=A6=96=E6=AC=A1=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E6=8A=A5=20NativeCommandError=20=E4=B8=AD=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PowerShell 7.3+ 默认会把"原生命令写了 stderr 且退出码非 0"当作终止性错误抛出, 即使用 2>$null 重定向也无法拦截(触发条件是退出码而非 stderr 内容是否被消费)。 脚本里 nssm stop/remove 针对尚不存在的服务(首次安装场景)必然会返回非 0, 这是预期内可忽略的失败,此前会导致 $ErrorActionPreference = "Stop" 直接中断脚本。 修复:脚本顶部关闭 $PSNativeCommandUseErrorActionPreference。 --- deploy/windows/install-nssm-services.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/deploy/windows/install-nssm-services.ps1 b/deploy/windows/install-nssm-services.ps1 index 2789311..a937181 100644 --- a/deploy/windows/install-nssm-services.ps1 +++ b/deploy/windows/install-nssm-services.ps1 @@ -14,6 +14,12 @@ $ErrorActionPreference = "Stop" +# PowerShell 7.3+ 默认会把"原生命令写了 stderr 且退出码非 0"当作终止性错误抛出 +# (即使用 2>$null 重定向也无法拦截,因为触发条件是退出码而非 stderr 内容)。 +# 下面 Install-NssmService 里首次安装时 `nssm stop`/`nssm remove` 针对尚不存在的 +# 服务必然会失败,这是预期内的可忽略错误,因此关闭该行为。 +$PSNativeCommandUseErrorActionPreference = $false + $Nssm = "nssm.exe" # 若 nssm 不在 PATH,改成绝对路径,如 "C:\tools\nssm-2.24\win64\nssm.exe" $RepoRoot = Resolve-Path (Join-Path $PSScriptRoot "..\..") $Powershell = (Get-Command powershell.exe).Source