Fixes #863 race condition between stdout and stderr