New to Ruby

S

Steve

I'm new to ruby and programming (although I did dabble in BASIC with my
Commodore 64 back in the 80's) I'm running Ruby with Windows XP. I'm
having a problem when I run this simple program:

puts 'Hello, world!'
puts ' '
puts 'Good-bye'

When I run the program, a window appears that says "Hello, world! Good-Buy"
and then the window immediately disappears. How do I get that window to
stay open after it has run the program?

Thanks for your help,

Steve
 
W

William James

Steve said:
I'm new to ruby and programming (although I did dabble in BASIC with my
Commodore 64 back in the 80's) I'm running Ruby with Windows XP. I'm
having a problem when I run this simple program:

puts 'Hello, world!'
puts ' '
puts 'Good-bye'

When I run the program, a window appears that says "Hello, world! Good-Buy"
and then the window immediately disappears. How do I get that window to
stay open after it has run the program?

Thanks for your help,

Steve

First, start a DOS-box (or command-line interface):

Start / All programs / Accessories / Command Prompt

Assuming your path is set correctly, then type:

ruby myprog.rb
 
J

Joe Van Dyk

I'm new to ruby and programming (although I did dabble in BASIC with my
Commodore 64 back in the 80's) I'm running Ruby with Windows XP. I'm
having a problem when I run this simple program:
=20
puts 'Hello, world!'
puts ' '
puts 'Good-bye'
=20
When I run the program, a window appears that says "Hello, world! Good-B= uy"
and then the window immediately disappears. How do I get that window to
stay open after it has run the program?

There might be an option (right click on the .rb file and choose
propeties) for making the window not close on exit.

Otherwise, an easy hack is to do something like
puts "hello world"
puts "we're quitting! press enter now"
gets
 
J

Jeff Wood

Or, simply click start, then run and then type "cmd" in the box and
hit enter...

That's the fastest way to a command prompt without adding a shortcut
to your desktop or quicklaunch bar...

j.

=20

=20
First, start a DOS-box (or command-line interface):
=20
Start / All programs / Accessories / Command Prompt
=20
Assuming your path is set correctly, then type:
=20
ruby myprog.rb
=20
=20
=20


--=20
"So long, and thanks for all the fish"

Jeff Wood
 
J

Jeff Wood

yeah, but that only works if you have a keyboard *WITH* a windows key ...=
=20

j.

Same as previous but quicker:
=20
WindowsKey + R (Same as Start -- Run)
type "cmd"
=20
=20
=20


--=20
"So long, and thanks for all the fish"

Jeff Wood
 
J

Jamal Hansen

I just tried this and it seemed to work, though it is kind of kludgy.=20
Copy the command prompt shortcut from your menu to the "send to"
folder.

Then take any file and send it to command prompt by right clicking.=20
It doesn't actually send anything, but it does open the command prompt
window.

Also Alt + S seems to open the start menu, but only if focus is on it. :(

Hope this helps,=20
Jamal
 
J

Jeff Wood

The normal keystroke for the start menu ( the one hidden by the
windows key ) is Ctrl-Escape.

Simply take a look at the files that were installed with the one-click
installer... Under Ruby->Ruby 1.8.2-15->Samples you will see a
hello.rb ... look at the code at the end ... There's a small bit of
code that does the whole wait for input...

If you need more than that, I would suggest writing a small batch file
to wrap the interpreter and put a pause at the end... same idea but
you then don't have to add anything to your scripts ...

Lots of ways to do it... just gotta choose one.

j.



I just tried this and it seemed to work, though it is kind of kludgy.
Copy the command prompt shortcut from your menu to the "send to"
folder.
=20
Then take any file and send it to command prompt by right clicking.
It doesn't actually send anything, but it does open the command prompt
window.
=20
Also Alt + S seems to open the start menu, but only if focus is on it. :(
=20
Hope this helps,
Jamal
=20

=20
=20


--=20
"So long, and thanks for all the fish"

Jeff Wood
 
D

Dave Burt

Jeff said:
The normal keystroke for the start menu ( the one hidden by the
windows key ) is Ctrl-Escape.

Simply take a look at the files that were installed with the one-click
installer... Under Ruby->Ruby 1.8.2-15->Samples you will see a
hello.rb ... look at the code at the end ... There's a small bit of
code that does the whole wait for input...

Just add the following line to the end of your program; it will wait for
[Enter].

gets
If you need more than that, I would suggest writing a small batch file
to wrap the interpreter and put a pause at the end... same idea but
you then don't have to add anything to your scripts ...

I prefer this alternative - you wont need to put "gets" at the end of all
your scripts. Put this ruby.bat in a directory in your path environment
variable before the real Ruby's directory (e.g. C:\Windows):

@echo off
ruby %*
pause

Cheers,
Dave
 
A

Alan Chen

If you used the windows one click installer, you'll probably have the
SciTe editor installed. With SciTe, open your program file and hit
the Tools/Go menu entry to run the script and preserve the output.

Cheers,
- alan
 
D

David Vallner

Steve said:
I'm new to ruby and programming (although I did dabble in BASIC with my
Commodore 64 back in the 80's) I'm running Ruby with Windows XP. I'm
having a problem when I run this simple program:

puts 'Hello, world!'
puts ' '
puts 'Good-bye'

When I run the program, a window appears that says "Hello, world! Good-Buy"
and then the window immediately disappears. How do I get that window to
stay open after it has run the program?

Thanks for your help,

Steve
I prefer to have the command prompt open - putting it in the quicklaunch
bar was the first thing I've done after I installed the system ;) IIRC,
the One Click Installer for Windows sets up both PATH and PATHEXT so you
can run a file called "hello.rb" by typing only "hello" at the command
prompt - just like you'd run a .BAT file.

David Vallner
 
M

Mike Woodhouse

Steve,

If you're using Scite as your editor (if you're not, it's bundled with
the Windows installer and should be on your Ruby menu somewhere) then
you might want to try this. Change the extension on your source file
from "rb" to "rbw". If you now run your script (F5 is the keyboard
shortcut) then the output is captured in the Scite output window. Plain
"rb" files will still open a quickly-disappearing Command window, which
is, as you've already discovered, tedious.

HTH,

Mike
 

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
474,177
Messages
2,570,954
Members
47,507
Latest member
codeguru31

Latest Threads

Top