Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How to View Output - Stop App

Reply
Thread Tools

How to View Output - Stop App

 
 
Rob Gu
Guest
Posts: n/a
 
      03-16-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 ]


Thank you!

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Shadowfirebird
Guest
Posts: n/a
 
      03-16-2011
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...

--
Snoopy: No problem is so big that it can't be run away from.

 
Reply With Quote
 
 
 
 
Jeremy Bopp
Guest
Posts: n/a
 
      03-16-2011
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 ]


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

 
Reply With Quote
 
Eric Christopherson
Guest
Posts: n/a
 
      03-16-2011
On Wed, Mar 16, 2011 at 3:30 PM, Rob Gu <(E-Mail Removed)> 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? =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.

 
Reply With Quote
 
Rob Gu
Guest
Posts: n/a
 
      03-16-2011
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.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Rob Gu
Guest
Posts: n/a
 
      03-16-2011
Eric Christopherson wrote in post #987808:
> On Wed, Mar 16, 2011 at 3:30 PM, Rob Gu <(E-Mail Removed)> 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 ]

>
> 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)

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to stop java service with command line parameter '-stop'? Will Java 1 11-02-2004 03:32 PM
How to make a week view and day view calendar just like month view calendar in .NET ? Parthiv Joshi ASP .Net Web Controls 1 07-06-2004 03:15 PM
How to stop a thread without using stop() Son KwonNam Java 11 04-09-2004 08:01 PM
Stop Debugging doesn't stop in ASP.NET Matt Theule ASP .Net 7 07-24-2003 07:38 PM



Advertisments