Use correct logic for piped input

Ref 94870e3eaa7b4f9e0b08da2b63f16885030a3edb