title: Powershell: Capturing standard out and error with Process object
body: <p>I want to start a Java program from PowerShell and get the results printed on the console.</p>
  
  <p>I have followed the instructions of this question: 
  <a href="https://stackoverflow.com/questions/8761888/powershell-capturing-standard-out-and-error-with-start-process">Capturing standard out and error with Start-Process</a></p>
  
  <p>But for me, this is not working as I expected. What I'm doing wrong?</p>
  
  <p>This is the script:</p>
  
  <pre><code>$psi = New-object System.Diagnostics.ProcessStartInfo
  $psi.CreateNoWindow = $true
  $psi.UseShellExecute = $false
  $psi.RedirectStandardOutput = $true
  $psi.RedirectStandardError = $true
  $psi.FileName = 'java.exe'
  $psi.Arguments = @("-jar","tools\compiler.jar","--compilation_level",   "ADVANCED_OPTIMIZATIONS", "--js", $BuildFile, "--js_output_file", $BuildMinFile)
  $process = New-Object System.Diagnostics.Process
  $process.StartInfo = $psi
  $process.Start() | Out-Null
  $process.WaitForExit()
  $output = $process.StandardOutput.ReadToEnd()
  $output
  </code></pre>
  
  <p>The <code>$output</code> variable is always empty (and nothing is printed on the console of course).</p>