Properly close stderr/stdout on redirect