java on linux - Have to press CtrlD twice -


string str = ""; bufferedreader bfr = new bufferedreader(new inputstreamreader(system.in)); int tempint = 0; try {     //the program cannot out while loop!     while((tempint = bfr.read()) != -1){         str += character.tostring((char)tempint);     } } catch(ioexception ioe) {     system.out.println(ioe); } //print input system.out.println(str); 

this code wrote reading user's input standard input. piece of code extracted playinput.jar , have written script play run jar. after run ./play in terminal(linux) , finish input, not contain enter, have press ctrl+d twice input printed out.

the same problem occurred when ran script called check, invoke ./play , send input via stdin. after ran ./check, hanged there , input cannot printed out.

could fix problem? thank you:)

that's how linux terminal works. has nothing java code.

if test out command cat > textfile, find unless @ beginning of line, ^d doesn't end file might expect to. (i don't know details of behavior, that's gist of it.)

the convention linux text file ends newline. can run problems if don't follow convention.

however, i'm not sure problem program hanging when send data using redirection. part more surprising me, since it's not interactive terminal behavior shouldn't issue.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -