Change the way to distinguish whether stdout is redirected or not