How to View Output - Stop App

R

Rob Gu

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 :( ]


Thank you!
 
S

Shadowfirebird

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 :( ]

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 <programname>' at the command prompt and I can see it fine; I imagine the same would be true of the Windows command mode screen...
 
J

Jeremy Bopp

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 :( ]

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
 
E

Eric Christopherson

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? =A0In 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 =3D gets()
puts "Well, hello there " + myname + "."
[so here it just closes out, but I want to see the greeting :( ]

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.
 
R

Rob Gu

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.
 
R

Rob Gu

Eric Christopherson wrote in post #987808:
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 :( ]

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top