Returning an error code from CMD to Powershell

前端 未结 3 1669
悲&欢浪女
悲&欢浪女 2021-01-18 11:19

I\'m working on a Mssql install script and I want to get the results of a silent mssql installation. In my PowerShell script I run this command:

$result = (s         


        
3条回答
  •  孤街浪徒
    2021-01-18 11:58

    Too late maybe but does this help?

    start /WAIT cmd.exe /C "YOUR-COMMAND-HERE" & if errorlevel 1 echo 'error occurred'
    

    you can also explicitly return an error code like this:

    start /WAIT cmd.exe /C "YOUR-COMMAND-HERE & exit MY-ERROR-CODE" & if errorlevel 1 echo 'error occurred'
    

提交回复
热议问题