Amzi! Prolog online help says:
If the end-of-file is reached (or [Ctrl-Z] is read from the terminal) then read behaves as though the atom '!EOF' had been read.
This is a test program.
test :- repeat, read(X), test2(X).
test2(X) :- atom(X), X == '!EOF', write('end of file'), !.
test2(X) :- write('You have just entered '), write(X), nl, fail.
?- test.
hello.
You have just entered hello
world.
You have just entered world
<- pressed [Ctrl-Z] and Enter
end of file
yes
?-