Find exit code for executing a cmd command through PowerShell

前端 未结 3 1913
再見小時候
再見小時候 2020-12-20 16:33

I am using a silent installation command to install software. I am running this command from PowerShell 3.0.

$silentInstall = C:\\Users\\Admin\\Documents\\Se         


        
3条回答
  •  春和景丽
    2020-12-20 16:53

    It depends on how the EXE file runs - sometimes it will kick off a separate process and return immediately, and in such cases this usually works -

    $p = Start-Process -FilePath  -ArgumentList  -Wait -NoNewWindow -PassThru
    $p.ExitCode
    

    Otherwise this usually works -

    &  
    $LASTEXITCODE
    

    Or sometimes this -

    & cmd.exe /c  
    $LASTEXITCODE
    

提交回复
热议问题