Missing grunt error output in when using powershell

28 Oct, 2013

If you're using grunt in a powershell script for continues integration you might run into issues with the error output. It's because of a bug regarding subprocess and stdout flushing in subprocess

Solution: Instead of writing directly to stdout we should pipe all output to a file, use the windows command type to output it and then delete the file. Like this.

  
grunt build --no-color > grunt.tmp
type grunt.tmp
del grunt.tmp
  

Why? When a subprocess breaks with an error is has not yet flushed all errors to the output since it will be done async. But the father process will kill the process and discard what ever it says afterwards. Which leaves us in a annoying state since why don't know why something failed.

But when we pipe the output to a file the node process will not do it async and the stdout will be sent to the father process before the error code.