Forum: Ruby Re: Full paths of Ruby interpreter and running script

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
F3b7b8756d0c7f71cc7460cc33aefaee?d=identicon&s=25 Berger, Daniel (Guest)
on 2006-04-17 22:31
(Received via mailing list)
> -----Original Message-----
> From: Jamal Mazrui []
> 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 ='kernel32', 'GetModuleFileName', 'LPL',
'L'), 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


This topic is locked and can not be replied to.