Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Minor fixes in startup script #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

anblanco
Copy link

@anblanco anblanco commented Oct 10, 2019

We were looking to integrate this code, and identified some fixes to the startup script we wanted to merge back upstream.

  1. In batch %ERRORLEVEL% is mutated on every read, so we replace the exit with EXIT /B %ERRORLEVEL% to return 0 or 1 based on powershell error

    • Correction - the error level was captured in the closure of the IF block, which would always evaluate to 0 since the powershell had not yet had a chance to run. Two options to fix would be
      1. Enable Delayed Expansion and replace %ERRORLEVEL% with !ERRORLEVEL!
      2. Simply move the exit to the bottom of the script.

In our case, we opted for the latter because that made the script easier to read

  1. Shutdown was not getting called because of Write-Host. Removed the Write-host block so that shutdowns can occur as expected.

%ERRORLEVEL% changes whenever the value is read.

The canonical form for reading the error level of a batch script and
returning it is EXIT /B %ERRORLEVEL%
@NoamDishon
Copy link

thanks anblanco. I came across the same issues and spent valuable time on this.... can someone merge this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants