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