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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Berger, Daniel (Guest)
on 2006-04-18 00:31
(Received via mailing list)
> -----Original Message-----
> From: Jamal M. [mailto:removed_email_address@domain.invalid]
> Sent: Monday, April 17, 2006 1:47 PM
> To: ruby-talk ML
> Subject: Re: Full paths of Ruby interpreter and running script

<snip>

> 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
This topic is locked and can not be replied to.