I'm looking to include a Windows .exe in my gem and call on that executable from within the gem. All the suggestions I've seen for including executable in gems calls for a hashbang to indicate which program should run the executable (typically "#!/usr/bin/env ruby "). I don't know of any program to call; I simply want to call the .exe. What would be the best way to do this?
2 Answers
Those are for *nix systems.
You can do
%x{full path to your .exe}
Use
$?
to get the exit status.
3 Comments
Joshua Galecki
Is there a way to refer to the executable within the gem via a relative path?
Mark Fraser
Relative to what? You can try calling it relative to your working dir. Or you can make sure it is in your path and call it directly.
Joshua Galecki
If I'm including foo.exe in the gem, is there a relative path from the wherever the command %x{path\to\foo.exe} executes (the working directory?) to stored-in-the-gem foo? Or is what I want not possible?
The hashbang can make a gem executable but isn't necessary to simply call the .exe within the gem itself. The calling module was in the gem's lib/ and the .exe in bin/. I was able to call the .exe from the ruby code with
exe_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "bin", "foo.exe"))
return_value = `#{exe_path}`
This works as long as you copy both lib/ and bin/ in the gemspec.