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.
2cf408af3f08d3575c9cd7697158a8f1?d=identicon&s=25 Jamal Mazrui (Guest)
on 2006-04-17 22: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
anyway.

Jamal


require 'Win32API'

app = Win32API.new("kernel32", "GetModuleFileName", ['L', 'P', 'L'],
'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.