From 575580d505d213a0fa9f0e6bb1444be7e72caf4b Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 22 Jun 2016 09:35:52 -0500 Subject: [PATCH] (GH-818) Wait for processes to exit + 2 seconds There are cases when the process has signalled it has exited, but it hasn't actually returned an exit code yet. Hold for 2 seconds to allow the process to fully exit before attempting to capture the exit code. --- .../helpers/functions/Get-ChocolateyUnzip.ps1 | 3 +++ .../helpers/functions/Start-ChocolateyProcessAsAdmin.ps1 | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/chocolatey.resources/helpers/functions/Get-ChocolateyUnzip.ps1 b/src/chocolatey.resources/helpers/functions/Get-ChocolateyUnzip.ps1 index 0d014c4dbc..90be131724 100644 --- a/src/chocolatey.resources/helpers/functions/Get-ChocolateyUnzip.ps1 +++ b/src/chocolatey.resources/helpers/functions/Get-ChocolateyUnzip.ps1 @@ -166,6 +166,9 @@ param( Unregister-Event -SourceIdentifier "LogOutput_ChocolateyZipProc" Unregister-Event -SourceIdentifier "LogErrors_ChocolateyZipProc" + # sometimes the process hasn't fully exited yet. + Start-Sleep 2 + $exitCode = $process.ExitCode Set-PowerShellExitCode $exitCode $process.Dispose() diff --git a/src/chocolatey.resources/helpers/functions/Start-ChocolateyProcessAsAdmin.ps1 b/src/chocolatey.resources/helpers/functions/Start-ChocolateyProcessAsAdmin.ps1 index 6cc416035d..768d6a86cf 100644 --- a/src/chocolatey.resources/helpers/functions/Start-ChocolateyProcessAsAdmin.ps1 +++ b/src/chocolatey.resources/helpers/functions/Start-ChocolateyProcessAsAdmin.ps1 @@ -156,7 +156,7 @@ Elevating Permissions and running [`"$exeToRun`" $wrappedStatements]. This may t $process = New-Object System.Diagnostics.Process $process.EnableRaisingEvents = $true - Register-ObjectEvent -InputObject $process -SourceIdentifier "LogOutput_ChocolateyProc" -EventName OutputDataReceived -Action $writeOutput | Out-Null + Register-ObjectEvent -InputObject $process -SourceIdentifier "LogOutput_ChocolateyProc" -EventName OutputDataReceived -Action $writeOutput | Out-Null Register-ObjectEvent -InputObject $process -SourceIdentifier "LogErrors_ChocolateyProc" -EventName ErrorDataReceived -Action $writeError | Out-Null #$process.StartInfo = New-Object System.Diagnostics.ProcessStartInfo($exeToRun, $wrappedStatements) @@ -191,6 +191,9 @@ Elevating Permissions and running [`"$exeToRun`" $wrappedStatements]. This may t # them to do so. Without this it never finishes. Unregister-Event -SourceIdentifier "LogOutput_ChocolateyProc" Unregister-Event -SourceIdentifier "LogErrors_ChocolateyProc" + + # sometimes the process hasn't fully exited yet. + Start-Sleep 2 $exitCode = $process.ExitCode $process.Dispose()