flush stdout before errors so that errors are correctly placed