How to View Output - Stop App

Discussion in 'Ruby' started by Rob Gu, Mar 16, 2011.

  1. Rob Gu

    Rob Gu Guest

    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/.
    Rob Gu, Mar 16, 2011
    #1
    1. Advertising

  2. 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.
    Shadowfirebird, Mar 16, 2011
    #2
    1. Advertising

  3. Rob Gu

    Jeremy Bopp Guest

    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
    Jeremy Bopp, Mar 16, 2011
    #3
  4. On Wed, Mar 16, 2011 at 3:30 PM, 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? =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.
    Eric Christopherson, Mar 16, 2011
    #4
  5. Rob Gu

    Rob Gu Guest

    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/.
    Rob Gu, Mar 16, 2011
    #5
  6. Rob Gu

    Rob Gu Guest

    Eric Christopherson wrote in post #987808:
    > On Wed, Mar 16, 2011 at 3:30 PM, 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 :( ]

    >
    > 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/.
    Rob Gu, Mar 16, 2011
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Theule

    Stop Debugging doesn't stop in ASP.NET

    Matt Theule, Jul 23, 2003, in forum: ASP .Net
    Replies:
    7
    Views:
    732
    Matt Theule
    Jul 24, 2003
  2. Son KwonNam
    Replies:
    11
    Views:
    2,599
    mr_organic
    Apr 9, 2004
  3. Will
    Replies:
    1
    Views:
    15,229
    Thomas Weidenfeller
    Nov 2, 2004
  4. Angus
    Replies:
    5
    Views:
    451
    Ben Bacarisse
    Jul 18, 2010
  5. Parthiv Joshi
    Replies:
    1
    Views:
    659
    Samuel L Matzen
    Jul 6, 2004
Loading...

Share This Page