added check for redirection input and output