title: Get Grunt Exit Code In PowerShell
body: <p>Basically the same as <a href="https://stackoverflow.com/questions/25443739/grunt-throw-compilation-error-to-powershell">this question</a>.  I am setting up a PowerShell script for TFS to run during the build.  When I execute the Grunt command through the command prompt, I get an error (as expected).  However, when running the command through PowerShell, no error is reported.</p>
  
  <p>My Powershell:</p>
  
  <pre><code>C:\...\grunt --gruntfile $pathOfGruntFile + "\gruntfile.js" prod-build
  Write-Output $?
  </code></pre>
  
  <p>This returns true every time.  I have also tried</p>
  
  <pre><code>C:\...\grunt --gruntfile $pathOfGruntFile + "\gruntfile.js" prod-build
  Write-Output $LASTEXITCODE
  </code></pre>
  
  <p>But that returns a null every time.</p>
  
  <p>I have also tried using Diagnostics.Process, as <a href="https://github.com/gruntjs/grunt/issues/117" rel="nofollow noreferrer">documented here</a>:</p>
  
  <pre><code>$process = New-Object Diagnostics.Process
  $process.StartInfo.FileName = "C:\...\npm\grunt"
  $process.StartInfo.Arguments = @('--gruntfile', "C:\...\gruntfile.js", 'prod-build')
  
  $process.Start()
  $process.Close()
  
  Start-Sleep -Seconds 20
  if ($process.ExitCode -ne 0) {throw $process.ExitCode}
  </code></pre>
  
  <p>When using this last method, it always throws "ScriptHalted", regardless of whether the Grunt process succeeds or fails.</p>
  
  <p>If the Grunt tasks fail, I need to stop the build.  How can I capture the Grunt exit code in PowerShell, or at least know if the Grunt script failed?</p>