How to get status of “Invoke-Expression”, successful or failed?

前端 未结 5 1199
故里飘歌
故里飘歌 2021-01-01 17:19

Invoke-Expression will return all the text of the command being invoked.

But how can I get the system return value of whether this command has been exec

5条回答
  •  旧巷少年郎
    2021-01-01 18:04

    In PowerShell you can evaluate execution status by inspecting the automatic variables

    $?
       Contains True if last operation succeeded and False otherwise.
    

    and/or

    $LASTEXITCODE
       Contains the exit code of the last Win32 executable execution.
    

    The former is for PowerShell cmdlets, the latter for external commands (like %errorlevel% in batch scripts).

    Does this help you?

提交回复
热议问题