Skip to content

Commit

Permalink
(GH-709) Get Exit code from PowerShell Host
Browse files Browse the repository at this point in the history
When interacting with a PowerShell host, ensure it returns the proper
exit code by calling the right method that will set it for both system
powershell and the internal host.
  • Loading branch information
ferventcoder committed Apr 24, 2016
1 parent 2272358 commit 07277ac
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/chocolatey.resources/chocolatey.resources.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@
<ItemGroup>
<EmbeddedResource Include="helpers\ChocolateyTabExpansion.ps1" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="helpers\functions\Set-PowerShellExitCode.ps1" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright © 2011 - Present RealDimensions Software, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Function Set-PowerShellExitCode {
param (
[int]$exitCode
)

$host.SetShouldExit($exitCode);
$env:ChocolateyExitCode = $exitCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,11 @@ private PowerShellExecutionResults run_host(ChocolateyConfiguration config, stri
case PipelineState.Failed:
case PipelineState.Stopping:
case PipelineState.Stopped:
host.SetShouldExit(1);
if (host.ExitCode == 0) host.SetShouldExit(1);
host.HostException = pipeline.PipelineStateInfo.Reason;
break;
case PipelineState.Completed:
host.SetShouldExit(0);
if (host.ExitCode == -1) host.SetShouldExit(0);
break;
}

Expand Down

0 comments on commit 07277ac

Please sign in to comment.