java - Scanner not working correctly in Mac OSX terminal -


i have hacky ant command user can run stuff. command prompts user input. in intellij, when testing, works correctly. when run ant target terminal, weird behavior. here code:

    scanner userin = new scanner(system.in);     printwriter writer = new printwriter(system.out);     writer.println(error + "  if continue load, data may in corrupted state.  continue? (y/n): ");     writer.flush();     string userresponse = userin.next();     while (!(userresponse.equalsignorecase("y") || userresponse.equalsignorecase("n")       || userresponse.equalsignorecase("yes") || userresponse.equalsignorecase("no"))) {       writer.println("invalid input.  please specify if continue load. (y/n): ");       writer.flush();       userresponse = userin.next();     }     return userresponse.equalsignorecase("y") || userresponse.equalsignorecase("yes"); 

when running ant command terminal, error message displayed when user enters input, either nothing happens, or have press enter bunch of times process. refuses read in input correctly. if type yes still loops forever, prompting inputs if user gave invalid input.

is kind of bug? inept @ using scanner?

edit: have tried using nextline() instead already. sometimes, not consistently java.util.nosuchelementexception: no line found exception. other times, works if press enter 10+ times.

i've been having same problem program (run via ant) create scanner when asked input, program seem loop , not accept input until terminated ctrl+c. turns out problem "fork" attribute in build.xml file. had fork="yes" , changed "no" or took out entirely scanner worked fine. hope helps!


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -