Is there a way to get out of a "hung" state in IRB?
Asked Answered
H

2

7

When using irb or rails console, I sometimes get stuck. For example, I forget a closing quote, so when I press enter, it's still waiting on that.

Sometimes I can get out of this (by suppyling the closing quote, for example), but sometimes I can't. If not, I usually do the following:

# Suspend the irb or console process
(Control + Z)

# Kill the last suspended process
kill -9 %

This is annoying and disrupts whatever I was doing in the console. What I'd like is an equivalent to Control + C on the command line, to say "forget that - give me a new prompt", so I can continue working in the console.

Is there a way to do this?

Hereford answered 2/12, 2011 at 14:54 Comment(3)
Control + C normally does the trick for me i must admit.Miraculous
@zoltarSpeaks - doesn't that kick you out of the console?Hereford
@Nathan nope. Control + D does (when entered enough times). It quits you also from terminal session, ssh session, su and all other types of sessions.Linkage
A
17

Press Control + D once or twice. That should do it.

Airline answered 2/12, 2011 at 14:58 Comment(4)
D for Dogbert? :) That seems to work. Do you know what it's actually doing?Hereford
:D. en.wikipedia.org/wiki/End-of-file Control+D sends an EOF character to the stream.Airline
Interesting. So I guess this fits with the "everything in Unix is a file" philosophy - my current terminal input included.Hereford
Interesting, I always thought that ctrl + D stood for disconnect.Marrufo
H
0

when you get recursion or Ctrl+D doesn't work

you can kill current process ($$)

exec("kill -9 #{$$}")
Harpy answered 9/5, 2020 at 16:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.