Invoke an exe from PowerShell and get feedback on success or failure

后端 未结 2 797
渐次进展
渐次进展 2020-12-03 09:22

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

More specifically I\'m trying to get devenv.exe to bu

相关标签:
2条回答
  • 2020-12-03 10:08

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

    • https://devblogs.microsoft.com/powershell/errorlevel-equivalent/
    0 讨论(0)
  • 2020-12-03 10:09
    .\YOUREXE.exe
    if($LASTEXITCODE -eq 0)
    {
        Write-Host "The last PS command executed successfully"
    } 
    else 
    {
        Write-Host "The last PS command failed"
    }
    
    0 讨论(0)
提交回复
热议问题