More accurate check of file descriptors

the "if fd" condition doesn't work for stdin(0), which perhaps must be redirected to /dev/null among stdout and stderr
Let's be more verbose and make a check for None