Fix stdout/stderr redirect after tests that print to stdout and stderr.
Merge pull request #8275 from danluu/stdout_redirect_broken

Fix stdout/stderr redirect after tests that print to stdout and stderr