Ruby script auto-closes at completion

J

John Tar

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
 
J

Jan Svitok

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.
 
J

Jeff Cohen

John said:
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
 
D

David Vallner

--------------enigFC7EA2AAE723C64B2258B512
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

John said:
Hi
=20
I am a newbie. I am trying to run some small ruby programs to learn a=20
bit about ruby.
=20
everytime i run the following program in windows it auto closes when it= =20
is done, so there is no time to see the final result
=20
is there any way to allow it to just freeze and not autoclose...the way= =20
i was doing it,is by putting a gets at the end....but i am sure there i= s=20
a better way
=20
thanks
=20
john
=20
code:
=20
=20
puts 'what is you first name?'
name =3D gets.chomp
a=3Dname.length.to_i
puts a
=20
puts 'what is you midlle name?'
mname=3Dgets.chomp
b=3Dmname.length.to_i
puts b
=20
puts 'what is you last midlle name?'
lname=3Dgets.chomp
c=3Dlname.length.to_i
puts c
=20
d=3Da+b+c
=20
puts 'there are ' + d.to_s + ' characters in your name:' +=20
mname.swapcase
=20
=20
=20
=20

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 Vallner


--------------enigFC7EA2AAE723C64B2258B512
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iD8DBQFFT7mKy6MhrS8astoRAtB4AJ4nlFylvlMxGeLsk9JV/vs2n/xSvACeNUcR
RKHBTZf1Nj11JvZLCFoRivg=
=KhEi
-----END PGP SIGNATURE-----

--------------enigFC7EA2AAE723C64B2258B512--
 
J

John Tar

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
 
J

Jeff Cohen

John said:
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 One-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
 
J

John Tar

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.
 
J

Jan Svitok

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 ;-)
 
J

John Tar

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
 
D

David Vallner

--------------enig238D2D29517274AEED5CBA13
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Jan said:
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 ;-)
=20

With ubiquitous abstract path name libraries, this strikes me as very sad=
=2E

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 Vallner


--------------enig238D2D29517274AEED5CBA13
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iD8DBQFFUREJy6MhrS8astoRAl/xAJ942zaNsbpd+k7ciwjzUbhFN/ZolACfUvrV
QrJpD1rJwv7rHZz5nNcQkM4=
=wJyF
-----END PGP SIGNATURE-----

--------------enig238D2D29517274AEED5CBA13--
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top