Re: Full paths of Ruby interpreter and running script


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