Forum: Ruby gets() makes my Ruby hang...?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
697bf46252c0f28ae8d347a8337423e3?d=identicon&s=25 PythonUsr (Guest)
on 2007-03-18 00:51
(Received via mailing list)
I'm using Ruby 1.8.5, with SciTE as my IDE.
I'm not a beginner at Ruby, I've been using it for about a year and a
half now.

I just got a new computer, so I installed Ruby onto it. So I open up
SciTE and type out a fairly long program. I run it, and all that pops
up is the cmd window that should compile my code. It hangs there
forever until I close it manually. I said "what is up with this?" and
I tried something. I had an inkling that it was gets() that was
causing my problems, so I made a new program:

name = gets("What is your name? ")
puts name

It still hangs! So, I make a new program, and put:

gets()

It hangs! When I make a program that says

puts("Hello!")

It works fine.

Help me!
188ff29b8682ec3a04e88d85a427300d?d=identicon&s=25 Tom Rauchenwald (Guest)
on 2007-03-18 01:15
(Received via mailing list)
"PythonUsr" <pythonusr@gmail.com> writes:

>
> name = gets("What is your name? ")
> puts name

I don't think that is what you want, more likely you want something
like:

puts "What is your name? "
name = gets
puts name

Look up the definition for gets, the argument for it is the record
separator, meaning that with your code you had to type What is your
name? to stop inputting.

> It still hangs! So, I make a new program, and put:
>
> gets()

Maybe because it waits for input?

Tom
017e05d1a49ffa59ea03e149e7af720b?d=identicon&s=25 Chris Shea (chrisshea)
on 2007-03-18 01:20
(Received via mailing list)
On Mar 17, 5:45 pm, "PythonUsr" <python...@gmail.com> wrote:
>
>
> It works fine.
>
> Help me!


There's a well-discussed issue with Windows, Scite, and stdin.  It's
Scite thats hanging.  If you run your script from the command line it
should work.  Searching this list for "scite windows stdin" I think
might find you a solution to getting gets working from Scite.

HTH,
Chris
697bf46252c0f28ae8d347a8337423e3?d=identicon&s=25 PythonUsr (Guest)
on 2007-03-18 13:26
(Received via mailing list)
On Mar 17, 8:14 pm, Tom Rauchenwald <its....@gmx.net> wrote:
> > causing my problems, so I made a new program:
>
> Tom
No. It doesn't take anything in. It just hangs there, until I exit the
window. I'll try it from the command line, but I've never had this
problem before.

> puts "What is your name? "
> name = gets
> puts name

Still, no. You think I wouldn't have tried something like that? xD
0f4b3fe3db6fe0c27150b32713f334dc?d=identicon&s=25 Kev (Guest)
on 2007-03-19 11:41
(Received via mailing list)
On Mar 18, 12:22 pm, "PythonUsr" <python...@gmail.com> wrote:
> > > SciTE and type out a fairly long program. I run it, and all that pops
>
> > >gets()
> > name = gets
> > puts name
>
> Still, no. You think I wouldn't have tried something like that? xD

I had this same problem, run it from the command line and it will be
fine.
428f96cc689eb7419bba3a8bbfcc222a?d=identicon&s=25 Stefan Mahlitz (Guest)
on 2007-03-19 22:09
(Received via mailing list)
PythonUsr wrote:
>
> name = gets("What is your name? ")
> puts name

You may want:

print "What is your name? "
$stdout.flush
name = gets()
puts name

and enter in the scite console.

You can ignore the cmd-window that pops up.

At least it does work for me

Stefan.
8ec4ee16cc9d2aa1cf9d5a18f4a72c43?d=identicon&s=25 Eric Jacoboni (Guest)
on 2007-03-20 21:17
(Received via mailing list)
"Chris Shea" <cmshea@gmail.com> writes:


> There's a well-discussed issue with Windows, Scite, and stdin.  It's
> Scite thats hanging.

Just put:

$stdin.sync = true

on top of your source file.
This topic is locked and can not be replied to.