Ruby script auto-closes at completion

Hi

I am a newbie. I am trying to run some small ruby programs to learn a
bit about ruby.

everytime i run the following program in windows it auto closes when it
is done, so there is no time to see the final result

is there any way to allow it to just freeze and not autoclose…the way
i was doing it,is by putting a gets at the end…but i am sure there is
a better way

thanks

john

code:

puts ‘what is you first name?’
name = gets.chomp
a=name.length.to_i
puts a

puts ‘what is you midlle name?’
mname=gets.chomp
b=mname.length.to_i
puts b

puts ‘what is you last midlle name?’
lname=gets.chomp
c=lname.length.to_i
puts c

d=a+b+c

puts ‘there are ’ + d.to_s + ’ characters in your name:’ +
mname.swapcase

John T. wrote:

Hi

everytime i run the following program in windows it auto closes when it
is done, so there is no time to see the final result

Sounds like you’re double-clicking the .rb file in Windows Explorer in
order to ru n it.

Instead, open up a command prompt and run your file manually:

c:>ruby myscript.rb

You’ll want to get familiar with the command prompt anyway, so you can
run irb and learn Ruby interactively.

Jeff
softiesonrails.com

Hi jeff

i have ruby installed in the c root. and the file is not in the c root.
i am trying to run it with elative paths, no paths and absolute paths,
and nothing seems to work.

the script is in a folder in my desktop.

i can’t copy the file to my c root, since i am not an admin at work

i tried running it from the folder where the file is, from where ruby
is,

when i do this in my mac at home, it dosen’t seem to happen

when i try to check to see if the ruby runs from the terminal with the
ruby -v comand, it dosen’t recognize it. i even try starting it up with
the ruby.exe file

nothing seems to work

thanks for you help

john

Jeff C. wrote:

John T. wrote:

Hi

everytime i run the following program in windows it auto closes when it
is done, so there is no time to see the final result

Sounds like you’re double-clicking the .rb file in Windows Explorer in
order to ru n it.

Instead, open up a command prompt and run your file manually:

c:>ruby myscript.rb

You’ll want to get familiar with the command prompt anyway, so you can
run irb and learn Ruby interactively.

Jeff
softiesonrails.com

John T. wrote:

Hi jeff

i have ruby installed in the c root. and the file is not in the c root.
i am trying to run it with elative paths, no paths and absolute paths,
and nothing seems to work.

First of all, installing anything to c:\ is not recommended on Windows.

Did you use the Ruby O.-Click Installer to install Ruby? If not, you
should go back and do that: http://rubyforge.org/projects/rubyinstaller/

Then the Ruby binaries will be in your search path and everything will
be easier.

Jeff
softiesonrails.com

Don’t run it from Explorer.

Start -> Run -> ‘cmd’, then navigate to the folder you want and type
‘ruby
your_script.rb’.

Jason

i did use the ruby one click installer. i just removed it …where do
you recommend i install it in. there is no clear documentation online as
to where in the HD it should be installed. what do you suggest?

thanks a lot chief…

p.s. as we speak, i am writing in this forum at home, and trying out the
installation on my Win.

Jeff C. wrote:

John T. wrote:

Hi jeff

i have ruby installed in the c root. and the file is not in the c root.
i am trying to run it with elative paths, no paths and absolute paths,
and nothing seems to work.

First of all, installing anything to c:\ is not recommended on Windows.

Did you use the Ruby O.-Click Installer to install Ruby? If not, you
should go back and do that: http://rubyforge.org/projects/rubyinstaller/

Then the Ruby binaries will be in your search path and everything will
be easier.

Jeff
softiesonrails.com

John T. wrote:

a better way
a=name.length.to_i
puts c

d=a+b+c

puts ‘there are ’ + d.to_s + ’ characters in your name:’ +
mname.swapcase

A method using less busywork to run the script itself would be adding:

puts “Press ENTER to close.”
gets

at the end of the script.

This should only be done in interactive programs, and is a workaround,
but it’s Good Enough.

David V.

On 11/7/06, John T. [email protected] wrote:

i did use the ruby one click installer. i just removed it …where do
you recommend i install it in. there is no clear documentation online as
to where in the HD it should be installed. what do you suggest?

Just install it in the default location (c:\ruby). It’s just not worth
the trouble installing it anywhere else. And NEVER install ruby into
Program Files or anything that has spaces in it - unless you are
willing to spend many happy hours debugging random problems somewhere
deep in the libraries :wink:

On 11/6/06, Jason R. [email protected] wrote:

Don’t run it from Explorer.

Start -> Run -> ‘cmd’, then navigate to the folder you want and type ‘ruby
your_script.rb’.

even just ‘your_script.rb’ or ‘your_script’, provided that ftype, PATH
and PATHEXT are set properly.

I just installed ruby again with the admin password

it works great

now scripts run in the same terminal

thanks to all you guys for your cooperation

Jan S. wrote:

Just install it in the default location (c:\ruby). It’s just not worth
the trouble installing it anywhere else. And NEVER install ruby into
Program Files or anything that has spaces in it - unless you are
willing to spend many happy hours debugging random problems somewhere
deep in the libraries :wink:

With ubiquitous abstract path name libraries, this strikes me as very
sad.

I dream of the day when I see makefiles that doesn’t choke on whitespace
in paths as commonplace. (Even sadder considering how widespread that
tool is. I blame Bourne shell and whoever thought making it do command
line processing when running as a script the same as when interactively
is a good idea.)

David V.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs