Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #12978

Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF?

From Jan Burse <janburse@fastmail.fm>
Newsgroups comp.lang.java.programmer
Subject Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF?
Date 2012-03-13 18:44 +0100
Organization albasani.net
Message-ID <jjo117$mpr$1@news.albasani.net> (permalink)
References <jjj3ke$jev$1@news.albasani.net> <b3k339-kf2.ln1@s.simpson148.btinternet.com> <jjnh2k$k2c$1@news.albasani.net> <3jc439-dc4.ln1@s.simpson148.btinternet.com>

Show all headers | View raw


Steven Simpson schrieb:
> I was going to suggest using Runtime.addShutdownHook(Thread) as a portable

In the final application the SIGINT should enter a monitor,
and the end-user can then choose among other things whether
he would like to abort the application or not.

But the effect is of course also seen with ordinary shut down
hooks.

When one overrides the SIGINT with the help of Signal/SignalHandler
the shutdown sequence is not anymore called. But the handler
is free to call System.exit() which will initiate the shut
down sequence.

 > Unfortunately, you still get the same read()==-1 on Windows, while
 > the read call doesn't return on Linux.

Yes, on Linux, it is as it should be.
The read call is blocking.

 > However, this could be a way to distinguish the 'fake' EOF
 > from a real one.  Having received -1, read again.  A real
 > one will produce -1 again, but the fake one will block or
 > yield more input.  For a real EOF, the behaviour seems the
 > same

Actually the standard input stream is special. It can return
-1 but will not close. And then after returning -1 it will
return normal user input. This works for Linux, Mac and
Windows.

So one can enter:

abc
<EOF>
def
<EOF>

Where <EOF> depends on the platform (^D on Mac and Linux,
^Z + Enter on Windows). When doing Buffered str = readLine().
One gets:

str = "abc"
str = null
str = "def"
str = null

The above is perfectly fine and intended. And one can write
applications that use recursive stream input.

The only issue on Windows is now that SIGINT injects a EOF.
I don't think that in my Monitor case a continued reading
might detect the SIGINT EOF. Since the SIGINT will not
perform a System.exit().

I guess that eventually in the non-Monitor case after a
System.exit() or so, the continued reading might show something,
IOException or so. Not sure.

But getting two EOF in general might be just the user
interaction, and not a SIGINT EOF. Getting two EOF is actually
a legal user interaction in my application. For example
on can recursively open a REPL, and then exit form it:

?- break.
[1] ?- break.
[2] ?- <EOF>
[1] ?- <EOF>
?-

Bye

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar


Thread

[Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-11 21:57 +0100
  Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-11 22:10 +0100
  Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-11 17:28 -0400
    Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-11 22:49 +0100
      Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-11 18:13 -0400
        Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-11 23:23 +0100
          Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-11 18:35 -0400
          Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? markspace <-@.> - 2012-03-11 15:51 -0700
            Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-12 10:58 +0100
              Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Lew <noone@lewscanon.com> - 2012-03-12 07:38 -0700
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-12 20:43 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-12 16:01 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2012-03-12 17:28 -0500
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 00:33 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Lew <lewbloch@gmail.com> - 2012-03-12 16:50 -0700
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 00:56 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-12 20:03 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 01:05 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-12 20:53 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 14:06 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 14:13 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-13 11:36 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 17:48 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 17:51 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-13 13:06 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-12 19:56 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 01:05 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Lew <lewbloch@gmail.com> - 2012-03-12 17:23 -0700
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-12 20:51 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Martin Gregorie <martin@address-in-sig.invalid> - 2012-03-13 02:33 +0000
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Patricia Shanahan <pats@acm.org> - 2012-03-12 20:39 -0700
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 14:17 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-13 11:38 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2012-03-12 21:59 -0500
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 14:20 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-13 11:28 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 17:42 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-13 13:16 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 18:17 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 18:19 +0100
              Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Silvio Bierman <silvio@moc.com> - 2012-03-12 16:21 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-12 20:35 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Robert Klemme <shortcutter@googlemail.com> - 2012-03-12 22:49 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Silvio Bierman <silvio@moc.com> - 2012-03-13 14:10 +0100
              Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-12 13:49 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-12 20:16 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-03-12 14:42 -0500
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-12 20:46 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-12 16:09 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-12 16:07 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-12 21:27 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-12 16:52 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-12 22:39 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-12 17:56 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Robert Klemme <shortcutter@googlemail.com> - 2012-03-12 23:02 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 00:18 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 00:19 +0100
  Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Steven Simpson <ss@domain.invalid> - 2012-03-13 10:28 +0000
    Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 14:11 +0100
      Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-13 11:41 -0400
        Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 17:43 +0100
          Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-13 13:03 -0400
            Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 18:20 +0100
              Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-13 13:36 -0400
              Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-03-13 12:42 -0500
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 18:51 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 18:51 +0100
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Arne Vajhøj <arne@vajhoej.dk> - 2012-03-13 19:53 -0400
                Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-14 01:21 +0100
      Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Steven Simpson <ss@domain.invalid> - 2012-03-13 17:26 +0000
        Re: [Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse <janburse@fastmail.fm> - 2012-03-13 18:44 +0100

csiph-web