question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pwsh as a dotnet global tool doesn't return the exit code correctly

See original GitHub issue

Steps to reproduce

On Linux, install PowerShell global tool as per the blog post from the PowerShell team:

https://devblogs.microsoft.com/powershell/introducing-powershell-as-net-global-tool/

dotnet tool install --global PowerShell

Then, run from bash:

pwsh "exit 1"; echo $LASTEXITCODE

Note: I’m not using -C because of issue #10355.

Expected behavior

It outputs 1.

Actual behavior

It outputs 0.

Environment data

$PSVersionTable:

Name                           Value
----                           -----
PSVersion                      6.2.2
PSEdition                      Core
GitCommitId                    6.2.2
OS                             Linux 4.4.0-18362-Microsoft #1-Microsoft Mon Mar 18 12:02:00 PST 2019
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Remarks

This works as expected on Linux if pwsh is not installed as a dotnet global tool.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
giggiocommented, Aug 27, 2019

@mklement0 yes! I fixed the description.

0reactions
jimmyca15commented, Nov 26, 2019

Is there a workaround for this somehow?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot .NET tool usage issues
If you're trying to run a global tool, check that the PATH environment variable on your machine contains the path where you installed...
Read more >
Why won't the "Exit" function work in my PowerShell code?
If you execute a script from the outside via PowerShell's CLI (e.g., pwsh -File script.ps1 ), the exit code set via exit $exitCode...
Read more >
Powershell Exit Code 1 = Get Output Failed - Forum
I having a tough time getting my script to correctly report the exit code to SAM 6.1.1. ... Exit codes 0 and 3...
Read more >
Installing PowerShell with one line as a .NET Core global tool
Tool 'powershell' (version '6.2.2') was successfully installed. ... Type 'help' to get help. PS /mnt/c/Users/Scott/Desktop> exit.
Read more >
Steps to return error codes on Powershell scripts
Steps to return error codes on Powershell scripts: Use the command Exit $LASTEXITCODE at the end of the powershell script to return the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found