Skip to content

Commit

Permalink
Fix: Process with an id of is not running errors
Browse files Browse the repository at this point in the history
This is chocolatey-archive/chocolatey#603.
Set the Error action preference to move on silently, then set it back
to what it was. This will allow the process wait check to fail without
any issues.
  • Loading branch information
ferventcoder committed Feb 20, 2015
1 parent 85cadce commit ea6f1ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Expand Up @@ -36,8 +36,14 @@ 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

# this is here for specific cases in Posh v3 where -Wait is not honored
try { if (!($process.HasExited)) { Wait-Process -Id $process.Id } } catch { }
$currentPreference = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'
if (!($process.HasExited)) {
Wait-Process -Id $process.Id
}
$ErrorActionPreference = $currentPreference

Write-Debug "`'$checksumExe`' exited with $($process.ExitCode)"

Expand Down
Expand Up @@ -95,10 +95,16 @@ param(
$unzipOps = {
param($7zip, $destination, $fileFullPath, [ref]$exitCodeRef)
Write-Debug "Calling '$7zip x -aoa -o`"$destination`" -y `"$fileFullPath`"'"
$process = Start-Process $7zip -ArgumentList "x -aoa -o`"$destination`" -y `"$fileFullPath`"" -Wait -WindowStyle Hidden -PassThru
$process = Start-Process "$7zip" -ArgumentList "x -aoa -o`"$destination`" -y `"$fileFullPath`"" -Wait -WindowStyle Hidden -PassThru
#$process = Start-Process $7zip -ArgumentList "x -aoa -o`"$destination`" -y `"$fileFullPath`"" -Wait -NoNewWindow -PassThru
# this is here for specific cases in Posh v3 where -Wait is not honored
try { if (!($process.HasExited)) { Wait-Process -Id $process.Id } } catch { }

# this is here for specific cases in Posh v3 where -Wait is not honored
$currentPreference = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'
if (!($process.HasExited)) {
Wait-Process -Id $process.Id
}
$ErrorActionPreference = $currentPreference

$exitCodeRef.Value = $process.ExitCode
}
Expand Down

0 comments on commit ea6f1ff

Please sign in to comment.