Fixed checking LASTEXITCODE.

This commit is contained in:
Shuai Lin 2016-12-17 00:31:34 +08:00
parent 6b5575bfe3
commit 916076409d

View file

@ -93,26 +93,26 @@ Currently the first branch must be a subprocess call.
#> #>
function do_if_not([scriptblock]$block_1, [scriptblock]$block_2) { function do_if_not([scriptblock]$block_1, [scriptblock]$block_2) {
$failed = $false $failed = $false
$script:LASTEXITCODE = 0 $global:LASTEXITCODE = $null
try { try {
& $block_1 & $block_1
} catch [System.Management.Automation.RemoteException] { } catch [System.Management.Automation.RemoteException] {
$failed = $true $failed = $true
} }
if ($failed -or !($script:LASTEXITCODE -eq 0)) { if ($failed -or !($global:LASTEXITCODE -eq 0)) {
& $block_2 & $block_2
} }
} }
function do_if([scriptblock]$block_1, [scriptblock]$block_2) { function do_if([scriptblock]$block_1, [scriptblock]$block_2) {
$failed = $false $failed = $false
$script:LASTEXITCODE = 0 $global:LASTEXITCODE = $null
try { try {
& $block_1 & $block_1
} catch [System.Management.Automation.RemoteException] { } catch [System.Management.Automation.RemoteException] {
$failed = $true $failed = $true
} }
if (!($failed) -and ($script:LASTEXITCODE -eq 0)) { if (!($failed) -and ($global:LASTEXITCODE -eq 0)) {
& $block_2 & $block_2
} }
} }