Re: Full paths of Ruby interpreter and running script


#1

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