1

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 2

1

Those are for *nix systems.

You can do

%x{full path to your .exe}

Use

$?

to get the exit status.

http://www.ruby-doc.org/core-1.9.3/Kernel.html

Sign up to request clarification or add additional context in comments.

3 Comments

Is there a way to refer to the executable within the gem via a relative path?
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.
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?
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.