Fix issue with encoding of output stream when output is being redirected/piped