tags:

views:

214

answers:

1

How can I run an executable in PowerShell and through an if statement decide whether it succeeded or failed?

More specifically I'm trying to get devenv.exe to build a solution from a PowerShell script and I need to know whether it succeeded or failed. By failed, I mean that the build has failed and I'm assuming devenv is sending something out to the shell (possibly in the stderr stream?)

I tried using &, Invoke-Expression and Invoke-Item and managed to get all of them to run the exe. But I was never able to get feedback on success / failures.

+4  A: 

Have you tried using the $LASTEXITCODE variable? It will contain the exit code of the last .exe that was invoked.

JaredPar
That did the trick. $lastexitcode -eq 0 when successful, 1 when building failed. :)
urig