You should explain in more detail what you expect. I am not surprised by the outcome: Your "piped" version reports reading from pipe data which indicates that can_read returned something with a true value. But then, you don't actually read from STDIN.