Skip to content

PowerShell exits with exit code 1 rather than returning $LASTEXITCODE when last process exit code is >0 #11461

@bgshacklett

Description

@bgshacklett

When running commands via pwsh -c '<command>', PowerShell will return an exit code of 1 in the event that <command> returns an exit code greater than 0. This is particularly problematic for tools like https://github.com/dense-analysis/ale/, which rely on an accurate exit code from the command which they spawn (a linter or fixer in this case).

Steps to reproduce

pwsh -c "bash -c 'exit 2'"; echo $LASTEXITCODE

Expected behavior

The exit code of the native application should be returned.

2

Actual behavior

PowerShell returns a generic "failure" exit code of 1.

1

Environment data


Name                           Value
----                           -----
PSVersion                      7.0.0-rc.1
PSEdition                      Core
GitCommitId                    7.0.0-rc.1
OS                             Darwin 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 201…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.10032.0, 6.0.0, 6.1.0, 6.2.0, 7.0.0-rc.1}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-AnsweredThe question is answered.Resolution-By DesignThe reported behavior is by design.WG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions