Obtaining ExitCode using Start-Process and WaitForExit instead of -Wait

后端 未结 6 1021
一生所求
一生所求 2020-11-29 01:29

I\'m trying to run a program from PowerShell, wait for the exit, then get access to the ExitCode, but I am not having much luck. I don\'t want to use -Wait with

6条回答
  •  無奈伤痛
    2020-11-29 02:16

    The '-Wait' option seemed to block for me even though my process had finished.

    I tried Adrian's solution and it works. But I used Wait-Process instead of relying on a side effect of retrieving the process handle.

    So:

    $proc = Start-Process $msbuild -PassThru
    Wait-Process -InputObject $proc
    
    if ($proc.ExitCode -ne 0) {
        Write-Warning "$_ exited with status code $($proc.ExitCode)"
    }
    

提交回复
热议问题