Joshua Galecki
Joshua Galecki

Reputation: 327

Using a Windows executable within a Ruby gem

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?

Upvotes: 1

Views: 446

Answers (2)

Joshua Galecki
Joshua Galecki

Reputation: 327

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.

Upvotes: 1

Mark Fraser
Mark Fraser

Reputation: 3198

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

Upvotes: 1

Related Questions