4

In groovy shell if you type this:

$ groovysh
Groovy Shell (2.3.7, JVM: 1.7.0_11)
Type ':help' or ':h' for help.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
groovy:000> (1..1234567)

and accidentally press Enter, you'll most likely ruin your current session without too much hope to be able to continue. That was a simple example - say you do something like:

(1..123456).collect { 'abc' * 80 }

You get the gist - and obviously you can be doing some things in the console where you have state you want to work with going on. Any way to tell groovy to stop, but not kill groovysh (which Ctrl+C does)?

Or alternatively tell it to print less every time unless more is asked for? Not sure what's possible, if anything - any hints?

levant pied
  • 3,886
  • 5
  • 37
  • 56
  • I was almost suggest groovy console. It had enable interrupt option and an interrupt button. Sadly it does not work. I use intellij for small scripting. It can pause/kill a running script.Not sure if that helps in your case. – Jayan Nov 01 '14 at 05:22
  • http://stackoverflow.com/questions/7035609/stopping-the-execution-of-a-groovy-script – Jayan Nov 01 '14 at 05:23

1 Answers1

1

In windows Groovysh doesn't seem to forward ctrl-c to the app as an interrupt signal. If I run this:

while(true)Thread.sleep(1000);

or this:

while(true);

in groovyconsole it can be interrupted, but when I do the same thing in Groovysh it cannot, it just hangs until I kill the process.

Some of this has to do with JLine which groovy uses for input, because if I disable jline like this:

groovysh -console=false

then ctrl-c kills the whole process instead of ignoring the ctrl-c. Maybe it's trying to catch and forward the ctrl-c and something is getting messed up with the forwarding part?

GroovyConsole can easily "Catch" the ctrl-c because windows doesn't deliver it as an interrupt, it's just input. for a console app like Groovysh, it's apparently pretty tough to catch a SIGINT (although it may be possible, I haven't personally tried it) Perhaps that's what they are trying to do with JLine and just have a bug in the windows implementation or haven't completed it yet...

It would be nice to have this fixed, but barring that I may write my own repl GUI like a GroovyConsole that maintains it's state like Groovysh.

Bill K
  • 62,186
  • 18
  • 105
  • 157
  • Thanks Bill K - looks like I should have mentioned, I'm on Linux. However, agreed - in both cases the problem is that it kills the session, i.e. I don't know of a way to interrupt the last processing instead of killing the whole session. – levant pied Nov 20 '14 at 16:03
  • If it's really important to you you might check the link on my post (Sorry it's a PDF, couldn't find the info anywhere else), it seems to be a way to get Java to allow you to handle the SIGINT instead of just bailing. You MIGHT be able to do this within a groovy class that you load into the shell by default. I'll probably try this approach when I have some time. – Bill K Nov 20 '14 at 17:14