Don't read from stdout when only attached to stdin

A fix for #1503