-----Original Message-----
From: Jamal M. [mailto:[email protected]]
Sent: Monday, April 17, 2006 1:47 PM
To: ruby-talk ML
Subject: Re: Full paths of Ruby interpreter and running script
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
Yep, that’ll work. For anyone who’s curious:
require ‘Win32API’
buf = 0.chr * 260
GetModuleFileName = Win32API.new(‘kernel32’, ‘GetModuleFileName’, ‘LPL’,
‘L’)
GetModuleFileName.call(0, buf, buf.size)
puts buf.strip # “c:\ruby\bin\ruby.exe”
That being said, I thought there was a way to do this from within Ruby
(without resorting to Win32API) but I can’t think of it now, assuming it
exists.
Regards,
Dan