Trouble running ruby programs

I’m a newbie programmer and I just downloaded ruby today. I must say I’m
impressed with its ease of use, but I have a problem.
When I try to run programs written in ruby, the window for the program
to run in pops up for a moment, but nothing happens and it closes. The
programs are written correctly and saved in the .rb format, and they
show up as ruby files in My Documents.
Can anyone help? I’m running Windows XP if that helps at all.

Can anyone help? I’m running Windows XP if that helps at all.

One solution is to run the program from the command line - so fire up a
terminal, and type

ruby my_program.rb

in the directory where my_program.rb is.

One more thing - you need to ensure that ruby is on your path. I did
this a few years ago for the last time, but I vaguely remember that it
can be accessed through properties of my computer and there environment
settings or something like that.

I am sure people on win32 can provide you better help than me, but until
then you can experiment with this :slight_smile:

Cheers,
Peter
__
http://www.rubyrailways.com :: Ruby and Web2.0 blog
http://scrubyt.org :: Ruby web scraping framework
http://rubykitchensink.ca/ :: The indexed archive of all things Ruby.

I tried going to the command prompt, making sure the file was in the
right folder, but when I typed in ruby “ri20min.rb”, it just didn’t do
anything. And I’m not sure what you’re talking about in the My Computer
properties. I looked but there was no environmental anything.

(btway, I’m the same person, but it wouldn’t let me reply without
registering)

Jacob G. wrote:

I tried going to the command prompt, making sure the file was in the
right folder, but when I typed in ruby “ri20min.rb”, it just didn’t do
anything. And I’m not sure what you’re talking about in the My Computer
properties. I looked but there was no environmental anything.

Have you tried entering the program name without any quotes?
Your path can be accessed by going to Start, Control Panel and then
System. From there select the Advanced tab and the Environment
Variables button. One of the variables in the top window should be
path. Double click on the path variable and scroll through it looking
for something ending with \ruby\bin.

Yeah, I did it eithout the quotes. (I’m not sure why I put them in my
post…)

But anyway, I went to environment variables, checked to make sure the
path was there and that ruby/bin was in it, and put it in the top window
(it was only in the bottom) but it still won’t work by clicking or with
command prompt…

Well, I’ll keep trying stuff I guess.

Jacob G. wrote:

Yeah, I did it eithout the quotes. (I’m not sure why I put them in my
post…)

But anyway, I went to environment variables, checked to make sure the
path was there and that ruby/bin was in it, and put it in the top window
(it was only in the bottom) but it still won’t work by clicking or with
command prompt…

Well, I’ll keep trying stuff I guess.

What do you get if you enter path from a command prompt? Does it show
\bin\ruby?

No… When I open command prompt it says C:\Documents and
Settings\Jacob>(which is the folder I have the program in)

And then I type

ruby ri20min.rb

and it does nothing.

The bin folder is in c:\ruby\bin, but I really don’t know how to go up a
folder.
It might help if I actually knew HOW to use the command prompt… TO THE
HELP MANUAL!!!

By the way, like I said in the first post, the window for the program
opens up, but it closwes a second or two later. The programs work in the
interactive ruby thing, but not as .rb files.

Well, I managed to figure out how to get where I want in command prompt
and whatnot, but I still can’t run the program…

On 6/8/07, Jacob G. [email protected] wrote:

folder.
It might help if I actually knew HOW to use the command prompt… TO THE
HELP MANUAL!!!


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

Maybe you should write a super simple ruby program and test with that.
Your program might have no output or something. Try

test.rb

#!/usr/bin/ruby

puts “Station!”

and do ruby test.rb

if it does nothing after that, then you know it must have something to
do with your commandline.

Also, if you feel like cheating you could either put getc() at the end
of every program (it will wait till you type something to go away.)
or make a wrapper that will do something like:

ruby #{file}
getc()

That way your sourcecode is not stuck in Borland C++ mode.

Also, the above code does not work. But there is surely a way to do it.

Jacob G. wrote:

folder.
It might help if I actually knew HOW to use the command prompt… TO THE
HELP MANUAL!!!

These Ruby-on-Windows FAQs might be useful:

Jacob G. wrote:

Okay, the program worked in the command prompt, (Station! appeared under
the command line) but I still have the problem with the window closing
before anything appears. Also, there’s a premade program in the bin
folder that DOES work in the window… is there some special code I need
to make a program able to open and run by itself?

Maybe you can end your scripts with:

gets

that way they will hang until you hit enter on the window? the problem
is that if you have an error, it won’t get to the ‘gets’ and won’t hang
open.

I find it better to open a command prompt and run the scripts from
there. Then you can ALT-TAB between the prompt and your editor. This way
will also show any errors…

Or you could use the Scite editor. You can specify “ruby” in the
Language drop down, then just hit F5 to execute your scripts. The output
shows up in a split window (not to mention the syntax highlighting…).

you can download it here (for windows):
http://prdownloads.sourceforge.net/scintilla/wscite173.zip?download

Okay, the program worked in the command prompt, (Station! appeared under
the command line) but I still have the problem with the window closing
before anything appears. Also, there’s a premade program in the bin
folder that DOES work in the window… is there some special code I need
to make a program able to open and run by itself?

On 6/8/07, Jacob G. [email protected] wrote:

Okay, the program worked in the command prompt, (Station! appeared under
the command line) but I still have the problem with the window closing
before anything appears. Also, there’s a premade program in the bin
folder that DOES work in the window… is there some special code I need
to make a program able to open and run by itself?


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

I think the issue here is that you aren’t understanding the console.
Normally when you write code you write some, and then run it, and then
write some, and then run it, etc etc. Generally people who use the
console a LOT will either open the file with a console editor and
leave the console open (obviously) and run the file when they want to
test what they have done, or they edit with something else, leave a
console open and run the previous command again to see the
differences. As for run by itself, I really think that the STDIN.getc
at the end of each program is the best you are gonna get for that.

Well, thanks for all your help guys. I think I’ve got it all pretty much
figured out. I still can’t get some of them to work in the interpreter,
but they run in command prompt, so I’m pretty much good.
But still, if you have any suggestions that’ve been missed as far as
making the interpreter work, feel free to post them.

Thanks again everyone!
-Hydro (Jacob)