# Gets() makes my Ruby hang...?

**URL:** <https://www.ruby-forum.com/t/gets-makes-my-ruby-hang/89168>\
**Category:** Ruby\
**Created:** [March 18, 2007, 12:51am UTC](https://www.ruby-forum.com/t/gets-makes-my-ruby-hang/89168 "2007-03-18T00:51:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![PythonUsr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@PythonUsr](https://www.ruby-forum.com/u/PythonUsr)\
**Post date:** [March 18, 2007, 12:51am UTC](https://www.ruby-forum.com/t/gets-makes-my-ruby-hang/89168/1 "2007-03-18T00:51:20Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![PythonUsr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@PythonUsr](https://www.ruby-forum.com/u/PythonUsr)\
**Post date:** [March 18, 2007, 1:15am UTC](https://www.ruby-forum.com/t/gets-makes-my-ruby-hang/89168/2 "2007-03-18T01:15:21Z")

</div>

“PythonUsr” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![PythonUsr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@PythonUsr](https://www.ruby-forum.com/u/PythonUsr)\
**Post date:** [March 18, 2007, 1:20am UTC](https://www.ruby-forum.com/t/gets-makes-my-ruby-hang/89168/3 "2007-03-18T01:20:22Z")

</div>

On Mar 17, 5:45 pm, “PythonUsr” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![PythonUsr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@PythonUsr](https://www.ruby-forum.com/u/PythonUsr)\
**Post date:** [March 18, 2007, 1:26pm UTC](https://www.ruby-forum.com/t/gets-makes-my-ruby-hang/89168/4 "2007-03-18T13:26:13Z")

</div>

On Mar 17, 8:14 pm, Tom R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![PythonUsr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@PythonUsr](https://www.ruby-forum.com/u/PythonUsr)\
**Post date:** [March 19, 2007, 10:09pm UTC](https://www.ruby-forum.com/t/gets-makes-my-ruby-hang/89168/5 "2007-03-19T22:09:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PythonUsr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@PythonUsr](https://www.ruby-forum.com/u/PythonUsr)\
**Post date:** [March 19, 2007, 11:41am UTC](https://www.ruby-forum.com/t/gets-makes-my-ruby-hang/89168/6 "2007-03-19T11:41:34Z")

</div>

On Mar 18, 12:22 pm, “PythonUsr” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![PythonUsr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c57346/32.png) [@PythonUsr](https://www.ruby-forum.com/u/PythonUsr)\
**Post date:** [March 20, 2007, 9:17pm UTC](https://www.ruby-forum.com/t/gets-makes-my-ruby-hang/89168/7 "2007-03-20T21:17:41Z")

</div>

“Chris S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
