Properly handle EOF on stdin