-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Request]: Non-Zero Exit Code For Console-Host #52
Comments
Hey there! With this last release I updated the code to break instead of exit. The reason for that was that PowerShell kept closing the entire window at the end. So for those running the script locally, breaking would keep the window open, and for scripts running in the background, it would exit with an exit code. So the challenge is... do we let the script close the PowerShell window but with the right code, or do we let the window remain by breaking but exiting with the wrong exit code. Ideally I should probably break up the script into additional functions and then run them in order so that the script naturally exits. As a workaround, I wonder if forcing an error code would work: # Set the exit code after the break
$global:LASTEXITCODE = 0 I'll have to test when I get back to my computer. |
Yea I thought that's probably why you wanted to avoid exiting on ConsoleHost, Bash has the same issues. You may want to look at the $MyInvocation cmdlet -
[In testing if it's run in a subprocess CommandOrigin will be "Internal"] |
Thanks! That worked great. Updating now. I'm not sure how it will appear in other languages, any idea? @uffemcev can you try this? Do you get $MyInvocation.CommandOrigin -eq "Runspace" |
@asheroto Hello, sorry for late answer. It's that what you need? |
Perfect, thank you! Just wanted to make sure it worked with non-English systems. Looks like they use |
Describe the feature or improvement you're requesting
When testing a script that uses winget-install to install winget if not present, I noticed that the captured process has an exit code of 1 not 0 although successful. When looking at the code, it's totally intentional because I'm running it in consolehost not sure why the logic is like this (its my first foray into a PS script) but it looks like Powershell sets the exit code to 1 when you exit via a break statement.
I'd like your script to return 0 regardless of if I'm launching from consolehost or not.
Here is the winget-install code:
Here is the part where I use it from my code, that I would like to not look for 0,1 yet only 0:
Additional context
No response
The text was updated successfully, but these errors were encountered: