Open AdamDanischewski opened 3 hours ago
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.
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