Skip to content

Commit 7005f5b

Browse files
authored
fix(): Check exit code for installs (#31)
Modify `Start-Process` code to check for a successful exit code. If the code is non-zero the installation fails. Fixes an issue where xampp installs were silently failing because there's no executable to verify.
1 parent cafe5e6 commit 7005f5b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

WebKitDev/Functions/Install-FromExe.ps1

+9-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@ function Install-FromExe {
4646
Write-Information -MessageData ('Installing {0} ...' -f $name) -InformationAction Continue;
4747
Write-Information -MessageData ('{0} {1}' -f $installerPath,($options -join ' ')) -InformationAction Continue;
4848

49-
Start-Process $installerPath -Wait -ArgumentList $options;
49+
# According to https://stackoverflow.com/a/23797762 caching the handle is required to get ExitCode
50+
$process = Start-Process $installerPath -PassThru -ArgumentList $options;
51+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Scope='Function')]
52+
$handle = $process.Handle;
53+
$process.WaitForExit();
54+
55+
if ($process.ExitCode -ne 0) {
56+
Write-Error ('{0} installer failed with exit code {1}' -f $name, $process.ExitCode) -ErrorAction Stop;
57+
}
5058

5159
# Update path
5260
Update-ScriptPath;

WebKitDev/Functions/Install-FromMsi.ps1

+9-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ function Install-FromMsi {
4949
Write-Information -MessageData ('Installing {0} ...' -f $name) -InformationAction Continue;
5050
Write-Information -MessageData ('msiexec {0}' -f ($msiArgs -join ' ')) -InformationAction Continue;
5151

52-
Start-Process msiexec -Wait -ArgumentList $msiArgs;
52+
# According to https://stackoverflow.com/a/23797762 caching the handle is required to get ExitCode
53+
$process = Start-Process msiexec -PassThru -ArgumentList $msiArgs;
54+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Scope='Function')]
55+
$handle = $process.Handle;
56+
$process.WaitForExit();
57+
58+
if ($process.ExitCode -ne 0) {
59+
Write-Error ('{0} installer failed with exit code {1}' -f $name, $process.ExitCode) -ErrorAction Stop;
60+
}
5361

5462
# Update path
5563
Update-ScriptPath;

0 commit comments

Comments
 (0)