BUG: fix issue with distutils.exec_command introduced in 1.7.0.

Closes gh-2999 and gh-2915.

There are several packages (nose, scipy.weave.inline, Sage inline Fortran) that
replace stdout, in which case it doesn't have a fileno method.  This method was
attempted to be used (change in gh-2766 to fix a py3k issue).