[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Proper way to allow Control-C to interrupt IO#gets

Lloyd Zusman

2/12/2008 4:29:00 PM

What is the canonical method for allowing an IO#gets call to be
immediately interrupted by Control-C? This doesn't seem to work as I am
expecting. Consider the following bit of ruby code:

trap("INT") do
puts "got signal INT"
end
puts "Enter some characters followed by newline:"
result = gets
puts result

When I run this and enter a few characters interspersed with an instance
of Control-C, the Control-C doesn't get recognized until after I hit
newline. Assuming that this program is in a file called "cctest",
here's what happens:

% ruby cctest
Enter some characters followed by newline:
[ here I enter AB^CDEFG, where "^C" is Control-C, which
doesn't cause the input to be aborted ]
ABDEFG <- This is what echos when I'm typing.
got signal INT <- This is what echos after I hit newline,
DEFG <- ... and this, as well.

In other words, the SIGINT resulting from Control-C doesn't get
processed at until after I type the newline.

I've searched for discussions of this on the net, but I haven't found
anything under a "ruby interrupt gets" Google search, because the word
"gets" is used so commonly in English in so many other contexts.

I know that I can write my own input handler or use something like the
HighLine package, but I'm wondering whether there's a way to cause
IO#gets to do what I want.

By the way, in case this is pertinent ...

% ruby --version
ruby 1.8.5 (2006-12-25 patchlevel 12) [i686-linux]

% uname -mor
2.6.9-022stab078.20-enterprise i686 GNU/Linux

Thanks in advance.


--
Lloyd Zusman
ljz@asfast.com
God bless you.


4 Answers

Lloyd Zusman

2/12/2008 4:47:00 PM

0

I left out a "Kernel.exit(0)" call in my test, but I still have the same
problemL

trap("INT") do
puts "got signal INT"
Kernel.exit(0)
end
puts "Enter some characters followed by newline:"
result = gets
puts result

% ruby cctest
Enter some characters followed by newline:
[ here I enter AB^CDEFG, where "^C" is Control-C, which
doesn't cause the input to be aborted ]
ABDEFG <- This is what echos when I'm typing.
got signal INT <- This is what echos after I hit newline.

In other words, the SIGINT still doesn't get processed until
after the newline is entered.


Lloyd Zusman <ljz@asfast.com> writes:

> What is the canonical method for allowing an IO#gets call to be
> immediately interrupted by Control-C? This doesn't seem to work as I am
> expecting. Consider the following bit of ruby code:
>
> trap("INT") do
> puts "got signal INT"
> end
> puts "Enter some characters followed by newline:"
> result = gets
> puts result
>
> When I run this and enter a few characters interspersed with an instance
> of Control-C, the Control-C doesn't get recognized until after I hit
> newline. Assuming that this program is in a file called "cctest",
> here's what happens:
>
> % ruby cctest
> Enter some characters followed by newline:
> [ here I enter AB^CDEFG, where "^C" is Control-C, which
> doesn't cause the input to be aborted ]
> ABDEFG <- This is what echos when I'm typing.
> got signal INT <- This is what echos after I hit newline,
> DEFG <- ... and this, as well.
>
> In other words, the SIGINT resulting from Control-C doesn't get
> processed at until after I type the newline.
>
> I've searched for discussions of this on the net, but I haven't found
> anything under a "ruby interrupt gets" Google search, because the word
> "gets" is used so commonly in English in so many other contexts.
>
> I know that I can write my own input handler or use something like the
> HighLine package, but I'm wondering whether there's a way to cause
> IO#gets to do what I want.
>
> By the way, in case this is pertinent ...
>
> % ruby --version
> ruby 1.8.5 (2006-12-25 patchlevel 12) [i686-linux]
>
> % uname -mor
> 2.6.9-022stab078.20-enterprise i686 GNU/Linux
>
> Thanks in advance.
>
>
> --
> Lloyd Zusman
> ljz@asfast.com
> God bless you.
>
>
>

--
Lloyd Zusman
ljz@asfast.com
God bless you.


Lamont Cranston

4/11/2012 1:03:00 AM

0

On 4/7/2012 11:32 AM, .MattB. wrote:
> On Sat, 07 Apr 2012 09:18:53 -0600, Yoorghis@Jurgis.net wrote:
>
>> On Fri, 06 Apr 2012 23:10:49 -0700, MattB.
>> <trdell1234@gmail.com.......> wrote:
>>
>>> Obama and the New Black Panthers
>>
>> "youtube" is now credible evidence (of anything?)
>
>
> Video is nice. I like Video. Much better than taking the word
> of some ass on a news network.

Translation: YouTube is not credible evidence of anything.

.MattB.

4/11/2012 2:41:00 AM

0

On Tue, 10 Apr 2012 18:02:41 -0700, Lamont Cranston
<TheShadow@SayNoToGOP.org> wrote:

>On 4/7/2012 11:32 AM, .MattB. wrote:
>> On Sat, 07 Apr 2012 09:18:53 -0600, Yoorghis@Jurgis.net wrote:
>>
>>> On Fri, 06 Apr 2012 23:10:49 -0700, MattB.
>>> <trdell1234@gmail.com.......> wrote:
>>>
>>>> Obama and the New Black Panthers
>>>
>>> "youtube" is now credible evidence (of anything?)
>>
>>
>> Video is nice. I like Video. Much better than taking the word
>> of some ass on a news network.
>
>Translation: YouTube is not credible evidence of anything.

Well unless you are using it. Looks pretty complete to me.

http://youtu.be/t...

Kill White babies is pretty plain.

MattB.

4/11/2012 4:15:00 AM

0

On Wed, 11 Apr 2012 03:54:55 +0000 (UTC), 2960 Dead <dead@gone.com>
wrote:

>On Tue, 10 Apr 2012 19:40:51 -0700, MattB wrote:
>
>> On Tue, 10 Apr 2012 18:02:41 -0700, Lamont Cranston
>> <TheShadow@SayNoToGOP.org> wrote:
>>
>>>On 4/7/2012 11:32 AM, .MattB. wrote:
>>>> On Sat, 07 Apr 2012 09:18:53 -0600, Yoorghis@Jurgis.net wrote:
>>>>
>>>>> On Fri, 06 Apr 2012 23:10:49 -0700, MattB.
>>>>> <trdell1234@gmail.com.......> wrote:
>>>>>
>>>>>> Obama and the New Black Panthers
>>>>>
>>>>> "youtube" is now credible evidence (of anything?)
>>>>
>>>>
>>>> Video is nice. I like Video. Much better than taking the word
>>>> of some ass on a news network.
>>>
>>>Translation: YouTube is not credible evidence of anything.
>>
>> Well unless you are using it. Looks pretty complete to me.
>>
>> http://youtu.be/t...
>>
>> Kill White babies is pretty plain.
>
>Just as a matter of curiosity, little bigot, what percentage of the black
>population do you think are members of the NBPP?


More than the whites belonging to the KKK today.
>
>
>
>
>
>--
>?Those who make peaceful revolution impossible, make violent revolution
>inevitable? -JFK