Ruby under Windows

Hi,

I’m trying to get my brother to try ruby. Currently he’s using Windows
2000 (he’s a Linux user, but he’s stuck witnh Windows for now). After
ruby is installed and you’ve written a program, how do you run it?

When I was there I tried clicking on the program. That caused a terminal
to come up and show the output. But the terminal quit right away.

I tried:

ruby prog.rb

But Windows didn’t recognize ruby as a program.

Also, is there a Windows equivalent of the ‘#!’ line?

Thanks for the help.

Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

Daniel Carrera wrote:

Hi,

I’m trying to get my brother to try ruby. Currently he’s using Windows
2000 (he’s a Linux user, but he’s stuck witnh Windows for now). After
ruby is installed and you’ve written a program, how do you run it?

When I was there I tried clicking on the program. That caused a terminal
to come up and show the output. But the terminal quit right away.

I tried:

ruby prog.rb

But Windows didn’t recognize ruby as a program.

What was the error message?
Is the ruby/bin directory in you PATH variable?
It should be, if you are using the Pragmatic Programmers Ruby installation.

Also, is there a Windows equivalent of the ‘#!’ line?

There’s no such thing - as far as I know.
But: You can associate files with the .rb suffix to the ruby
interpreter. If you do this you can omit the ‘ruby’ part in the command
line and run a program like this:

prog.rb

HTH

Stephan

“Daniel Carrera” dcarrera@math.umd.edu wrote in message

After ruby is installed and you’ve written a program, how do you run it?

Make sure that the PATH variable has C:\RUBY\BIN in it (assuming ruby is
installed on C: drive under the RUBY folder). Open up a command shell by

1.going to Start >> Run
2.entering CMD at the Open: prompt
3.and clicking OK

At the command prompt (say C:> ) you will have to enter:
ruby prog.rb

When I was there I tried clicking on the program. That caused a terminal
to come up and show the output. But the terminal quit right away.

I tried:

ruby prog.rb

But Windows didn’t recognize ruby as a program.

That is probably because the PATH environment system variable was NOT
modified to locate ruby.
To modify this variable

  1. look for “My Computer” icon on the desktop
  2. Right click and choose “Properties” from the pop-up
  3. Select the “Advanced” tab
  4. Click on “Environment variables”
  5. In the “System Variables” list select the PATH variable
  6. Click on “Edit”
  7. Modify the “Variable Value”
  8. Click OK repeatedly till you are out of the dialog.
  9. Close all the command shells that may be open
  10. Open a new session and enter “PATH” at the prompt
  11. Verify that “C:\ruby\bin” is in the semi-colon separated PATH
    components.
  12. If it is, then you should be able to do
    C:>ruby -e “puts PATH.split(‘;’)”
    PATH=C:\WINDOWS\system32
    C:\WINDOWS
    C:\WINDOWS\system32\WBEM
    c:\ruby\bin
    ^^^^^^^^^
    This is the proof that Ruby is in the path.

I think if you install Ruby on Windows using Andy’s one click installer, it
will take care of this.

Also, is there a Windows equivalent of the ‘#!’ line?

There is a notion of “file associations” which is effectively the same
thing. In File Explorer if you select any file with .rb extension

  1. right click to get a pop-up
  2. then select “Open with” you get
  3. to “Choose” Program to “associate” the binary which will be used to open
    this file type.

Thanks for the help.

HTH,
– shanko

“Daniel Carrera” dcarrera@math.umd.edu wrote in message
news:Pine.GSO.4.44.0301181153390.639-100000@hardy.math.umd.edu…

Hi,

I’m trying to get my brother to try ruby. Currently he’s using Windows
2000 (he’s a Linux user, but he’s stuck witnh Windows for now). After
ruby is installed and you’ve written a program, how do you run it?

There have been various answers already - however the thread leaves the
impression that it’s mighty difficult to get Ruby running on Windows. This
is not the case.

Assuming you have Windows 2000 or Windows XP, the Pragmatic Programmer
single click installer should configure the system such that you can execute
…rb and .rbw files directly. Note that .rbw files do not use a command
prompt and are expected to launch a GUI such as fox.

After installation it should be possible to use Explorer to browse into the
rubyb\samples\FxRuby directory, click on a random .rbw file and launch a GUI
sample application written in Ruby.

If it doesn’t work directly after installation, a reboot might be necessary.

Mikkel

ruby prog.rb

But Windows didn’t recognize ruby as a program.

What was the error message?

“Program not found” (or something along those lines).

Is the ruby/bin directory in you PATH variable?
It should be, if you are using the Pragmatic Programmers Ruby installation.

HHmmm…
Do you have to reboot the computer to make it work?

Also, is there a Windows equivalent of the ‘#!’ line?

There’s no such thing - as far as I know.
But: You can associate files with the .rb suffix to the ruby
interpreter. If you do this you can omit the ‘ruby’ part in the command
line and run a program like this:

prog.rb

That’s cool too. How do you do that? Is that done automatically by the
Pragmatic programers install? It think it must be because, like I said,
it did run ruby when I clicked on the program name.

Does that also require a reboot?

Thanks.

Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

···

On Sun, 19 Jan 2003, Stephan Kämper wrote:

Shashank, thank you for your thorough answers. I just learned a fair bit
about Windows.

Cheers,
Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137

···

On Sun, 19 Jan 2003, Shashank Date wrote:

“Daniel Carrera” dcarrera@math.umd.edu wrote in message

After ruby is installed and you’ve written a program, how do you run it?

Make sure that the PATH variable has C:\RUBY\BIN in it (assuming ruby is
installed on C: drive under the RUBY folder). Open up a command shell by

1.going to Start >> Run
2.entering CMD at the Open: prompt
3.and clicking OK

At the command prompt (say C:> ) you will have to enter:
ruby prog.rb

When I was there I tried clicking on the program. That caused a terminal
to come up and show the output. But the terminal quit right away.

I tried:

ruby prog.rb

But Windows didn’t recognize ruby as a program.

That is probably because the PATH environment system variable was NOT
modified to locate ruby.
To modify this variable

  1. look for “My Computer” icon on the desktop
  2. Right click and choose “Properties” from the pop-up
  3. Select the “Advanced” tab
  4. Click on “Environment variables”
  5. In the “System Variables” list select the PATH variable
  6. Click on “Edit”
  7. Modify the “Variable Value”
  8. Click OK repeatedly till you are out of the dialog.
  9. Close all the command shells that may be open
  10. Open a new session and enter “PATH” at the prompt
  11. Verify that “C:\ruby\bin” is in the semi-colon separated PATH
    components.
  12. If it is, then you should be able to do
    C:>ruby -e “puts PATH.split(‘;’)”
    PATH=C:\WINDOWS\system32
    C:\WINDOWS
    C:\WINDOWS\system32\WBEM
    c:\ruby\bin
    ^^^^^^^^^
    This is the proof that Ruby is in the path.

I think if you install Ruby on Windows using Andy’s one click installer, it
will take care of this.

Also, is there a Windows equivalent of the ‘#!’ line?

There is a notion of “file associations” which is effectively the same
thing. In File Explorer if you select any file with .rb extension

  1. right click to get a pop-up
  2. then select “Open with” you get
  3. to “Choose” Program to “associate” the binary which will be used to open
    this file type.

Thanks for the help.

HTH,
– shanko

Hi,

Also, is there a Windows equivalent of the ‘#!’ line?

There is a notion of “file associations” which is effectively the same
thing. In File Explorer if you select any file with .rb extension

  1. right click to get a pop-up
  2. then select “Open with” you get
  3. to “Choose” Program to “associate” the binary which will be used to open
    this file type.

Note that redirection doesn’t work with associated programs. I
don’t know this is a feature of Windows or not.

c:\home\nobu>assoc .rb=RubyScript
.rb=RubyScript

c:\home\nobu>ftype RubyScript=ruby.exe %1 %*
RubyScript=ruby.exe %1 %*

c:\home\nobu>type foo.rb
#!/usr/bin/ruby
print $_ while gets

c:\home\nobu>ruby foo.rb foo.rb
#!/usr/bin/ruby
print $_ while gets

c:\home\nobu>ruby foo.rb < foo.rb
#!/usr/bin/ruby
print $_ while gets

c:\home\nobu>foo.rb foo.rb
#!/usr/bin/ruby
print $_ while gets

c:\home\nobu>foo.rb < foo.rb
C:/home/nobu/foo.rb:2:in `gets’: Bad file descriptor (Errno::EBADF)
from C:/home/nobu/foo.rb:2

···

At Sun, 19 Jan 2003 02:50:32 +0900, Shashank Date wrote:


Nobu Nakada