How to View Output - Stop App

Greetings, total noob question I’m sure. I’m trying to run a simple
example in a console, but how do I tell it to stop so I can view the
output? In C# I think I could just return false or something, but what
do you do in Ruby?

puts “Hello, world. What is your name?”
myname = gets()
puts "Well, hello there " + myname + “.”
[so here it just closes out, but I want to see the greeting :frowning: ]

Thank you!

Excerpts from Rob Gu’s message of Wed Mar 16 20:30:52 +0000 2011:

Greetings, total noob question I’m sure. I’m trying to run a simple
example in a console, but how do I tell it to stop so I can view the
output? In C# I think I could just return false or something, but what
do you do in Ruby?

puts “Hello, world. What is your name?”
myname = gets()
puts "Well, hello there " + myname + “.”
[so here it just closes out, but I want to see the greeting :frowning: ]

I think it very much depends what you are using as an editor. Also your
OS.

Here in Linux I can just run a program with 'ruby ’ at the
command prompt and I can see it fine; I imagine the same would be true
of the Windows command mode screen…

On 3/16/2011 15:30, Rob Gu wrote:

Greetings, total noob question I’m sure. I’m trying to run a simple
example in a console, but how do I tell it to stop so I can view the
output? In C# I think I could just return false or something, but what
do you do in Ruby?

puts “Hello, world. What is your name?”
myname = gets()
puts "Well, hello there " + myname + “.”
[so here it just closes out, but I want to see the greeting :frowning: ]

If you’re running ruby without any arguments and then typing your script
in directly, you need to send the end of file character at the end of
the script. Since you mention C#, you’re probably running on Windows
with the cmd console. In that case, type Ctrl-Z and then Enter. If
you’re at a Unix terminal or running under Cygwin, type Ctrl-D.

A better way to try things out is to put them into a file and then run
the file using ruby. This will allow you to easily go back and make
changes without having to retype everything.

An even better way to try simple stuff out like this is to use irb. The
irb program gives you a prompt that takes ruby code line-by-line and
executes it, giving you a result after each line or complete statement.
It’s very handy.

-Jeremy

Thanks for the replies. I installed Ruby 1.9.2 on XP. I did save the
code to a .rb file and am opening it with Ruby Interpreter. I just don’t
get how to get it to stop to view output, or why it just closes out.

On Wed, Mar 16, 2011 at 3:30 PM, Rob Gu [email protected] wrote:

Greetings, total noob question I’m sure. I’m trying to run a simple
example in a console, but how do I tell it to stop so I can view the
output? In C# I think I could just return false or something, but what
do you do in Ruby?

puts “Hello, world. What is your name?”
myname = gets()
puts "Well, hello there " + myname + “.”
[so here it just closes out, but I want to see the greeting :frowning: ]

I assume you mean that you double-click on the script’s icon, a cmd
window appears, you type in your name, and then the cmd window
disappears. If so, just put ‘gets’ at the end of the script; that’ll
make it wait until you press Enter to close it.

Eric C. wrote in post #987808:

On Wed, Mar 16, 2011 at 3:30 PM, Rob Gu [email protected] wrote:

Greetings, total noob question I’m sure. I’m trying to run a simple
example in a console, but how do I tell it to stop so I can view the
output? In C# I think I could just return false or something, but what
do you do in Ruby?

puts “Hello, world. What is your name?”
myname = gets()
puts "Well, hello there " + myname + “.”
[so here it just closes out, but I want to see the greeting :frowning: ]

I assume you mean that you double-click on the script’s icon, a cmd
window appears, you type in your name, and then the cmd window
disappears. If so, just put ‘gets’ at the end of the script; that’ll
make it wait until you press Enter to close it.

Exactly, thank you everyone! (Didn’t notice this before my last reply)