Backport stderr/stdout fixes from v3.0.x