1

I have this java code:

import java.util.Scanner;
public class Main {
    public static void main(String [] args) {
        Scanner in = new Scanner(System.in);
        String line;
        while (in.hasNextLine()) {
            line = in.nextLine();
        }
    }
}

And I run it from jar file using ant:

<target name="run" depends="compile">
    <java jar="./myfile.jar" fork="true"/>
</target>

But when I hit Ctrl+D on keyboard, the while loop does not break. How can I detect EOF from keyboard when I am using ant tool?

user207421
  • 305,947
  • 44
  • 307
  • 483
Tehryn
  • 57
  • 1
  • 10

1 Answers1

0

I was just running into this problem using an input file configured in the Eclipse run configuration, common tab.

As it turns out, if you're using Windows, you might need to type:

ctrl+z 

after clicking in the Eclipse console in order to cause Eclipse to send an end of file signal for standard input.

EOF isn't conveyed by a character anymore like it used to be on VERY old systems but instead by a signal.

See

https://stackoverflow.com/questions/12389518/representing-eof-in-c-code/12389581#:~:text=EOF%20is%20not%20a%20character,of%20the%20stream%20is%20reached

and

How to send EOF via Windows terminal

beaudet
  • 886
  • 1
  • 10
  • 13