From 69d2f6ab535cc3ddddfe0cde0011586fc2b2b9b5 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Fri, 11 Jul 2014 09:09:26 -0500 Subject: [PATCH] (GH-516) Guard all Wait-Process if posh v3+ - This adds Wait-Process to anywhere Start-Process is called with a guard that this should only be done in PowerShell v3+. --- src/functions/Chocolatey-Pack.ps1 | 3 ++- src/functions/Chocolatey-Push.ps1 | 3 ++- src/functions/Chocolatey-Python.ps1 | 5 +++-- src/helpers/functions/Get-CheckSumValid.ps1 | 1 + src/helpers/functions/Get-ChocolateyUnzip.ps1 | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/functions/Chocolatey-Pack.ps1 b/src/functions/Chocolatey-Pack.ps1 index c697443..78ee7ab 100644 --- a/src/functions/Chocolatey-Pack.ps1 +++ b/src/functions/Chocolatey-Pack.ps1 @@ -10,7 +10,8 @@ param( Write-Host "Calling `'$nugetExe $packageArgs`'." - Start-Process $nugetExe -ArgumentList $packageArgs -NoNewWindow -Wait -RedirectStandardOutput $logFile -RedirectStandardError $errorLogFile + $process = Start-Process $nugetExe -ArgumentList $packageArgs -NoNewWindow -Wait -RedirectStandardOutput $logFile -RedirectStandardError $errorLogFile -PassThru + if ($host.Version.Major -ge 3) { Wait-Process -InputObject $process } $nugetOutput = Get-Content $logFile -Encoding Ascii foreach ($line in $nugetOutput) { diff --git a/src/functions/Chocolatey-Push.ps1 b/src/functions/Chocolatey-Push.ps1 index 3873515..616cabd 100644 --- a/src/functions/Chocolatey-Push.ps1 +++ b/src/functions/Chocolatey-Push.ps1 @@ -17,7 +17,8 @@ param( Write-Host "Calling `'$nugetExe $packageArgs`'. This may take a few minutes. Please wait for the command to finish." -ForegroundColor $Note -BackgroundColor Black - Start-Process $nugetExe -ArgumentList $packageArgs -NoNewWindow -Wait -RedirectStandardOutput $logFile -RedirectStandardError $errorLogFile + $process = Start-Process $nugetExe -ArgumentList $packageArgs -NoNewWindow -Wait -RedirectStandardOutput $logFile -RedirectStandardError $errorLogFile -PassThru + if ($host.Version.Major -ge 3) { Wait-Process -InputObject $process } $nugetOutput = Get-Content $logFile -Encoding Ascii foreach ($line in $nugetOutput) { diff --git a/src/functions/Chocolatey-Python.ps1 b/src/functions/Chocolatey-Python.ps1 index b166404..fd1ea07 100644 --- a/src/functions/Chocolatey-Python.ps1 +++ b/src/functions/Chocolatey-Python.ps1 @@ -36,8 +36,9 @@ param( #& cmd.exe $packagesArgs | Tee-Object -FilePath $chocoInstallLog Write-Host "Opening minimized PowerShell window and calling `'cmd.exe $packageArgs`'. If progress is taking a long time, please check that window. It also may not be 100% silent..." -ForegroundColor $Warning -BackgroundColor Black - Start-Process -FilePath "$($env:windir)\System32\WindowsPowerShell\v1.0\powershell.exe" -ArgumentList "-NoProfile -ExecutionPolicy unrestricted -Command `"cmd.exe $packageArgs | Tee-Object -FilePath `'$chocoInstallLog`'`"" -Wait -WindowStyle Minimized - + $process = Start-Process -FilePath "$($env:windir)\System32\WindowsPowerShell\v1.0\powershell.exe" -ArgumentList "-NoProfile -ExecutionPolicy unrestricted -Command `"cmd.exe $packageArgs | Tee-Object -FilePath `'$chocoInstallLog`'`"" -Wait -WindowStyle Minimized -PassThru + if ($host.Version.Major -ge 3) { Wait-Process -InputObject $process } + Create-InstallLogIfNotExists $chocoInstallLog $installOutput = Get-Content $chocoInstallLog -Encoding Ascii foreach ($line in $installOutput) { diff --git a/src/helpers/functions/Get-CheckSumValid.ps1 b/src/helpers/functions/Get-CheckSumValid.ps1 index 3bfc9ac..f9cc810 100644 --- a/src/helpers/functions/Get-CheckSumValid.ps1 +++ b/src/helpers/functions/Get-CheckSumValid.ps1 @@ -20,6 +20,7 @@ param( Write-Debug "Calling command [`'$checksumExe`' -c$checksum `"$file`"] to retrieve checksum" $process = Start-Process "$checksumExe" -ArgumentList " -c=`"$checksum`" -t=`"$checksumType`" -f=`"$file`"" -Wait -WindowStyle Hidden -PassThru + if ($host.Version.Major -ge 3) { Wait-Process -InputObject $process } Write-Debug "`'$checksumExe`' exited with $($process.ExitCode)" diff --git a/src/helpers/functions/Get-ChocolateyUnzip.ps1 b/src/helpers/functions/Get-ChocolateyUnzip.ps1 index 2b6263d..e1662af 100644 --- a/src/helpers/functions/Get-ChocolateyUnzip.ps1 +++ b/src/helpers/functions/Get-ChocolateyUnzip.ps1 @@ -80,7 +80,7 @@ param( $unzipOps = { param($7zip, $destination, $fileFullPath, [ref]$exitCodeRef) $p = Start-Process $7zip -ArgumentList "x -o`"$destination`" -y `"$fileFullPath`"" -Wait -WindowStyle Hidden -PassThru - Wait-Process -InputObject $p + if ($host.Version.Major -ge 3) { Wait-Process -InputObject $p } $exitCodeRef.Value = $p.ExitCode }