I appreciate these suggestions, but found that they do not actually
solve my problem. If a full Ruby installation is done with the One
Click Installer, the code does return the folder containing the Ruby
interpreter (C:\Ruby\bin by default). In distributing a Ruby program I
am developing, however, I intend to distribute only the minimum set of
files for running the program. Through trial and error, I have found
that these are ruby.exe, msvcrt-ruby18.dll, and the particular .so or
.rb library files that my main script.rb file calls.
In testing the rbconfig technique, I copied these files, including
rbconfig.rb, into a temporary folder, c:\TestRuby. When I ran a test
program at the command prompt, the correct path was not given. It
should have been C:\TestRuby\rubyw.exe for the interpreter (or
C:\TestRuby\test.rb for the script file).
Windows has an API function, GetModuleFileName , that returns the full
path of the running executable. I may be able to wrap an API call using
the Win32API library, but prefer a native Ruby approach if possible.
Jamal
···
-----Original Message-----
From: ara.t.howard@noaa.gov [mailto:ara.t.howard@noaa.gov]
Sent: Monday, April 17, 2006 12:16 PM
To: ruby-talk ML
Subject: Re: Full paths of Ruby interpreter and running script
On Tue, 18 Apr 2006, Berger, Daniel wrote:
-----Original Message-----
From: Jamal Mazrui [mailto:Jamal.Mazrui@fcc.gov]
Sent: Monday, April 17, 2006 9:54 AM
To: ruby-talk ML
Subject: Full paths of Ruby interpreter and running scriptI've looked through and experimented with predefined global
constants, but so far have not figured how to get the full
path and name of the Ruby interpreter and/or main script file
from within a running program. I want to distribute a program
that can be installed in a folder chosen by the user. The
program would save configuration information in the same
folder. In order to find the configuration file at runtime, I
thought I would query the full path of the Ruby interpreter
or script file. In case it makes a difference, I'm using Windows.Jamal
Is this what you're after?
require 'rbconfig'
include Configputs CONFIG['bindir'] # c:/ruby/bin
Regards,
i use this
c = ::Config::CONFIG
File::join(c['bindir'], c['ruby_install_name']) << c['EXEEXT']
cheers.
-a
--
be kind whenever possible... it is always possible.
- h.h. the 14th dali lama