Checking exit code of last command using “if” statement

前端 未结 2 1800
慢半拍i
慢半拍i 2020-12-09 09:32

I want to check the status of last command and based on the exit code, the commands will be executed further.

The last command execute was:

$hiveJob         


        
2条回答
  •  佛祖请我去吃肉
    2020-12-09 09:44

    From Get-Help about_If:

    Syntax The following example shows the If statement syntax:

       if ()
           {}
       [elseif ()
           {}]
       [else
           {}]
    

    Note: the square brackets around the elseif and else indicate they are optional.

    Assign your returned object to a variable:

    $hiveJob = Start-AzureHDInsightJob -Cluster $clusterName -JobDefinition  $hiveJobDefinition
    Wait-AzureHDInsightJob -Job $hiveJob -WaitTimeoutInSeconds 5400
    $Result = Get-AzureHDInsightJobOutput -Cluster $clusterName -JobId $hiveJob.JobId -StandardOutput
    

    Then

    if ($Result.ExitCode -eq 0)
      {
        #More commands
      }
    

提交回复
热议问题