2

I want to invoke a VisualBuild build from PowerShell and get it's last exit code.

I invoke the Build using.

Start-Process -FilePath $VisualBuild -ArgumentList "/b Somescript.bld" -PassThru -NoNewWindow

I already tried using try catch mechanism but this lead my LastExitCode to be 0 even if the Build Failed.

When using something like

$BuildProcess = Start-Process -FilePath $VisualBuild -ArgumentList "/b Somescript.bld" -PassThru -NoNewWindow
Write-Host "$($BuildProcess.ExitCode)"

my Script get's stuck after executing and displaying that the Build has failed but the Output of the LastExitCode is never displayed.

The $VisualBuild Variable holds the full Path to the VisBuildCmd.exe

r4d1um
  • 528
  • 1
  • 9
  • 32
  • 2
    Possible duplicate of [Obtaining ExitCode using Start-Process and WaitForExit instead of -Wait](https://stackoverflow.com/questions/10262231/obtaining-exitcode-using-start-process-and-waitforexit-instead-of-wait) – Tomalak Aug 15 '17 at 06:31

1 Answers1

1

I think you just need to get your last exit code immediately after your command and store it in a variable:

Start-Process -FilePath $VisualBuild -ArgumentList "/b Somescript.bld" -PassThru -NoNewWindow
$MyLastExitCode = $LastExitCode

Write-Host "LastExitCode: $MyLastExitCode"

I have had previous issues where I ran a command before I displayed my last exit code and it was always 0. It might be a similar issue.

Shawn Esterman
  • 2,292
  • 1
  • 10
  • 15