Skip to content

Commit 45f80dc

Browse files
committed
fix the update script exit code
1 parent 0ab250c commit 45f80dc

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.0
1+
0.5.1

update/windows-update.ps1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ param(
2020

2121
$mock = $false
2222

23+
function ExitWithCode($exitCode) {
24+
$host.SetShouldExit($exitCode)
25+
Exit
26+
}
27+
2328
Set-StrictMode -Version Latest
2429

2530
$ErrorActionPreference = 'Stop'
@@ -28,7 +33,7 @@ trap {
2833
Write-Output "ERROR: $_"
2934
Write-Output (($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$','ERROR: $1')
3035
Write-Output (($_.Exception.ToString() -split '\r?\n') -replace '^(.*)$','ERROR EXCEPTION: $1')
31-
Exit 1
36+
ExitWithCode 1
3237
}
3338

3439
if ($mock) {
@@ -41,10 +46,10 @@ if ($mock) {
4146
Write-Output "Synthetic reboot countdown counter is at $count"
4247
Set-Content $mockWindowsUpdatePath (--$count)
4348
Write-Output 'Rebooting...'
44-
Exit 101
49+
ExitWithCode 101
4550
}
4651
Write-Output 'No Windows updates found'
47-
Exit 0
52+
ExitWithCode 0
4853
}
4954

5055
Add-Type @'
@@ -103,7 +108,7 @@ function ExitWhenRebootRequired($rebootRequired = $false) {
103108
Write-Output 'Pending Reboot detected. Waiting for the Windows Modules Installer to exit...'
104109
Wait-Condition {(Get-Process -ErrorAction SilentlyContinue TiWorker | Measure-Object).Count -eq 0}
105110
Write-Output 'Rebooting...'
106-
Exit 101
111+
ExitWithCode 101
107112
}
108113
}
109114

0 commit comments

Comments
 (0)