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.
Jamal M. (Guest)
on 2006-04-18 00:55
(Received via mailing list)
Thanks, folks!  By coincidence, I had just successfully wrapped the API
call myself and was about to share the solution.  Dan's code may be
better (I'm still learning Ruby), but I'll go ahead and post mine below


require 'Win32API'

app ="kernel32", "GetModuleFileName", ['L', 'P', 'L'],
handle = 0
size = 260
buffer = ' ' * size
result = app.Call(handle, buffer, size)
puts(result) # number of characters returned to buffer (20 in this case)

path = buffer.unpack("Z*").to_s # unpack to single string
puts(path) # C:\TestRuby\ruby.exe
This topic is locked and can not be replied to.