ruby calc.rb or just calc.rb

Discussion in 'Ruby' started by Kaye Ng, Jul 26, 2010.

  1. Kaye Ng

    Kaye Ng Guest

    Beginner here (in ANY programming language), so pls bear with me.

    Please see the first example on this page.
    http://pine.fm/LearnToProgram/?Chapter=01

    It says to type in ruby calc.rb

    I find it doesn't work.
    What works are:
    calc.rb
    or simply
    calc

    Am I wrong? I saved the calc.rb in G:\Ruby\Practice
    I opened command prompt in Accessories, went to G:\Ruby\Practice ,
    then typed ruby calc.rb

    G:\Ruby\Practice>ruby calc.rb
    'ruby' is not recognized as an internal or external command,
    operable program or batch file.

    so I typed calc.rb and it worked.
    calc also worked.

    So is the example wrong or am I doing it wrong?

    Thanks guys!
    --
    Posted via http://www.ruby-forum.com/.
     
    Kaye Ng, Jul 26, 2010
    #1
    1. Advertising

  2. Re: ruby calc.rb or just calc.rb

    On Mon, Jul 26, 2010 at 12:29 PM, Kaye Ng <> wrote:
    > Beginner here (in ANY programming language), so pls bear with me.
    >
    > Please see the first example on this page.
    > http://pine.fm/LearnToProgram/?Chapter=01
    >
    > It says to type in ruby calc.rb
    >
    > I find it doesn't work.
    > What works are:
    > calc.rb
    > or simply
    > calc
    >
    > Am I wrong? I saved the calc.rb in G:\Ruby\Practice
    > I opened command prompt in Accessories, went to G:\Ruby\Practice ,
    > then typed ruby calc.rb
    >
    > G:\Ruby\Practice>ruby calc.rb
    > 'ruby' is not recognized as an internal or external command,
    > operable program or batch file.


    I'm not a Windows expert, but what this is saying is that "ruby", the
    ruby executable, is not in your PATH.
    You could put it in your path, IIRC, in some global settings (search
    for setting environment variables in Windows)

    > so I typed calc.rb and it worked.


    This is probably because you (or the Ruby installation program) have
    associated .rb programs to the ruby executable (you can check this in
    the File Types Association in some contextual menu in the Explorer, I
    think).

    > calc also worked.


    I'm totally guessing here, but it might be that the Windows cmd
    expands a command with existing files in the current directory, if it
    doesn't find a command like that?

    Jesus.
     
    Jesús Gabriel y Galán, Jul 26, 2010
    #2
    1. Advertising

  3. Re: ruby calc.rb or just calc.rb

    I agree with Jesús Gabriel y Galán :

    the ruby command will only work if you put the "$path\ruby\bin" in your
    PATH
    -> right click on computer, then properties, advanced, environment
    variables, edit your PATH variable and add you ruby path ex :
    c:\ruby\bin;.....
    dont delete or modify existing path ^^

    it's may be usefull if you want see ruby errors


    If you only type the filename like calc.rb, windows will try to run the
    file with the assiociated program in your case, ruby, so it will work
    fine, but if you will get an error, the cmd window will be close with
    your ruby application.

    If you only run calc, without the ".rb" windows will try ton run
    runnable file with calc name ... That could be a problem if for example
    you use ocra to get a ruby exe (named calc.exe) and you still have your
    calc.rb in the same folder.

    I dont know how windows will react ... it may ask you if you want run
    the .exe or the .rb, or send you an error, or maybe run the .exe ..
    --
    Posted via http://www.ruby-forum.com/.
     
    Guillaume Bloss, Jul 26, 2010
    #3
  4. Kaye Ng

    James Guest

    Re: ruby calc.rb or just calc.rb

    [Note: parts of this message were removed to make it a legal post.]

    As a curiosity issue, what version of Windows are you using? Because Windows
    7, at least, has a different way you can edit the user specific PATH
    variable rather than the system PATH variable.
    Control Panel -> User accounts -> Change my environment variables
     
    James, Jul 26, 2010
    #4
  5. Kaye Ng

    Kaye Ng Guest

    thanks guys

    To James, I'm still on windows xp.

    I tried putting the calc.rb file inside the bin folder, and "ruby
    calc.rb" worked, as well as "calc" and "calc.rb"

    Is this what you guys were saying?

    The tutorial didn't say anything about the bin folder or where exactly
    to save the programs. It only said to make a folder wherein my programs
    could be saved, and that's what I did. But then it instructed to type
    "ruby calc.rb" and I got confused.

    I still don't understand the logic behind it.
    Do I have to bother with this?
    Do I always have to save my programs in the bin folder?

    Please excuse the ignorance. I'm a novice.

    --
    Posted via http://www.ruby-forum.com/.
     
    Kaye Ng, Jul 27, 2010
    #5
  6. Re: thanks guys

    On Tue, Jul 27, 2010 at 8:43 AM, Kaye Ng <> wrote:
    > To James, I'm still on windows xp.
    >
    > I tried putting the calc.rb file inside the bin folder, and "ruby
    > calc.rb" worked, as well as "calc" and "calc.rb"
    >
    > Is this what you guys were saying?
    >
    > The tutorial didn't say anything about the bin folder or where exactly
    > to save the programs. =A0It only said to make a folder wherein my program=

    s
    > could be saved, and that's what I did. =A0But then it instructed to type
    > "ruby calc.rb" and I got confused.
    >
    > I still don't understand the logic behind it.
    > Do I have to bother with this?
    > Do I always have to save my programs in the bin folder?
    >
    > Please excuse the ignorance. I'm a novice.


    No problem, we were all novices at some point in time. When you type
    "ruby" in the cmd window, Windows has to know to which program you
    refer to. For this, it uses the environment variable PATH, which
    contains a list of folders to search for executables. When you are in
    any folder in your system and type the name of a program, it searches
    in the current folder and then in all folders in that variable until
    it finds a suitable named program to run. If it doesn't find one, it
    spits the message "ruby is not recognized, etc, etc". A way to solve
    it so that you can call ruby from wherever folder, is to add the path
    to the ruby executable to your PATH environment variable. Others have
    explained how to do that in Windows (there are some menus to click and
    so on).

    With this, then you can place your rb files wherever you want, and
    call the ruby executable from that folder.

    Hope this helps,

    Jesus.
     
    Jesús Gabriel y Galán, Jul 27, 2010
    #6
  7. Re: thanks guys

    If you don't know how to change PATH variable in Windows (then you
    should learn it of course), then you can install Ruby again from
    http://rubyinstaller.org/ but this time check also the checkbox, which
    says something about "add to PATH". For some reason this is not
    checked by default.

    And please don't put your Ruby scripts into Ruby\bin directory - it
    will be a mess after a while.

    -----
    Jarmo Pertman
    IT does really matter - http://www.itreallymatters.net
     
    Jarmo Pertman, Jul 27, 2010
    #7
  8. Kaye Ng

    Kaye Ng Guest

    Kaye Ng, Jul 28, 2010
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tat
    Replies:
    0
    Views:
    368
  2. walterbyrd
    Replies:
    1
    Views:
    368
    Damjan
    Apr 10, 2006
  3. Ark Khasin

    Is it just me or just Microsoft?

    Ark Khasin, Jul 15, 2007, in forum: C++
    Replies:
    24
    Views:
    752
    Lionel B
    Jul 16, 2007
  4. Ark Khasin

    Is it just me or just Microsoft?

    Ark Khasin, Jul 15, 2007, in forum: C Programming
    Replies:
    42
    Views:
    1,129
    user923005
    Jul 17, 2007
  5. apanloco
    Replies:
    0
    Views:
    85
    apanloco
    Mar 19, 2007
Loading...

Share This Page