Path: csiph.com!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Jan Burse Newsgroups: comp.lang.java.programmer Subject: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Date: Sun, 11 Mar 2012 21:57:50 +0100 Organization: albasani.net Lines: 48 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net pILPgKbUovXEPhaiX3QksuBXLlp6Ybpfn8iBpMWKvONBrnT2exQUN6ZapMAewqQ1uVpUuPaaYKj86us9/TNeNdxzTyuWqxoEpFg3SKZPSPll2dKdTqUt/DYSxHvrMZRt NNTP-Posting-Date: Sun, 11 Mar 2012 20:57:50 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="hWB6+j2S59tWFzQpZro3oy1flpJt2Vxfa5rrNrcZ7B3W+tRgTayc/7QES5V7hDoDSEcFcIp3zPW2few5uOt/PVJ9sGAacgB6RQ3kdvNbbdWwvs6ekrSYt5DWIuIM5Q/Z"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Firefox/10.0.2 SeaMonkey/2.7.2 Cancel-Lock: sha1:ILK6LVV59jnkE/NMl7Ei7LhKB7o= Xref: csiph.com comp.lang.java.programmer:12873 Dear All, Just running the following test program: CtrlCRunner ctrl = new CtrlCRunner(); ctrl.installCtrlC( new Runnable() { public void run() { /* do nothing ! */ } } ); FileInputStream fs = new FileInputStream(FileDescriptor.in); byte[] buf = new byte[256]; for (;;) { System.out.print("test: "); int len = fs.read(buf); String str = new String(buf,0,Math.max(0,len)); System.out.println("len = "+len+", buf = "+str+", buf[0]="+buf[0]); if ("exit".equals(str.trim())) break; } ctrl.deinstallCtrlC(); Noticed that ^C and ^Z both deliver EOF. When pressing ^C test: len = -1, buf = , buf[0]=0 When pressing ^Z and ENTER: test: ^Z len = -1, buf = , buf[0]=0 How could I distinguish the two in Java? Best Regards BTW: It does not happen on Linux and Mac OS with ^C and ^D, I only see this happen currently on Windows 7. Sounds similar to the following problem: Inconsistent raw_input behavior after Ctrl-C http://www.gossamer-threads.com/lists/python/python/781893