davetron5000/optparse-plus

Bundle exec doesn't work reliably on Windows

Closed this issue ยท 10 comments

I'm following along with the tutorial in the wiki and whenever I run the bundle exec bin/fullstop command (in my case portal_builder) I get this error message .

bundle exec .\bin\portal_builder  
Unfortunately, a fatal error has occurred. Please see the Bundler
troubleshooting documentation at http://bit.ly/bundler-issues. Thanks!
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/cli.rb:503:in 'exec': Exec format error -     
.\bin\portal_builder (Errno::ENOEXEC)
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/cli.rb:503:in 'exec'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor/task.rb:27:in 'run'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor/invocation.rb:120:in 
'invoke_task'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor.rb:344:in 'dispatch'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor/base.rb:434:in 'start'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/bin/bundle:20:in
'block in <top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/friendly_errors.rb:3:in 'with_friendly_errors'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/bin/bundle:20:in
'<top (required)>'
    from C:/Ruby193/bin/bundle:23:in 'load'
    from C:/Ruby193/bin/bundle:23:in '<main>'
PS C:\projects\***\***\services\portal\trunk\portal\portal_builder> bundle exec .\bin\portal_builder --help
bundler: command not found: .\bin\portal_builder
Install missing gem executables with 'bundle install'
PS C:\projects\***\***\services\portal\trunk\portal\portal_builder> bin/portal_builder
PS C:\projects\***\***\services\portal\trunk\portal\portal_builder> ruby bin/portal_builder
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in 'require':
cannot load such file -- portal_builder.rb (LoadError)
    from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in 'require'
    from bin/portal_builder:5:in '<main>'
PS C:\projects\***\****\services\portal\trunk\portal\portal_builder> bundle exec bin/portal_builder
Unfortunately, a fatal error has occurred. Please see the Bundler
troubleshooting documentation at http://bit.ly/bundler-issues. Thanks!
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/cli.rb:503:in 'exec': Exec format error -     
bin/portal_builder (Errno::ENOEXEC)
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/cli.rb:503:in 'exec'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor/task.rb:27:in 'run'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor/invocation.rb:120:in    
'invoke_task'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor.rb:344:in 'dispatch'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor/base.rb:434:in 'start'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/bin/bundle:20:in
'block in <top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/friendly_errors.rb:3:in 'with_friendly_errors'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/bin/bundle:20:in
'<top (required)>'
    from C:/Ruby193/bin/bundle:23:in 'load'
    from C:/Ruby193/bin/bundle:23:in '<main>'

If I include --help at the end of that I get an even stranger message.

`bundle exec bin/portal_builder --help
bundler: command not found: bin/portal_builder
Install missing gem executables with `bundle install`

Whoa. First off, I don't have access to Windows, and haven't used it in
quite some time. It's possible there's some windows error in here.
Assuming that there's not, however, you can check a few things:

  • Any chance you generated binstubs? If you do, it overwrites the
    methadone-generated bin file and strange things happen.
  • Try doing RUBYLIB=lib bin/portal_builder
  • Try adding require 'rubygems' before the first require in
    bin/portal_builder

It seems like whatever is going on with manipulating the path isn't working
properly. You could create the gem and install it locally and see if
that helps?

I had a heck of time getting Ruby working on my wife's laptop when writing
up this stuff, so I apologize that I don't know more about Windows.

Dave


Buy My Book: http://www.awesomecommandlineapps.com
My Blog: http://www.naildrivin5.com/blog
Fork me on Github: http://davetron5000.github.com

On Fri, Apr 19, 2013 at 1:05 PM, Tyler Thrailkill
notifications@github.comwrote:

I'm following along with the tutorial in the wiki and whenever I run the
bundle exec bin/fullstop command (in my case portal_builder) I get this
error message .
bundle exec .\bin\portal_builder
Unfortunately, a fatal error has occurred. Please see the Bundler
troubleshooting documentation at http://bit.ly/bundler-issues. Thanks!
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/cli.rb:503:in
exec': Exec format error - .\bin\portal_builder (Errno::ENOEXEC) from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/cli.rb:503:in exec'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor/task.rb:27:in
run' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor/invocation.rb:120:in invoke_task'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor.rb:344:in
dispatch' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor/base.rb:434:in start'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/bin/bundle:20:in
block in <top (required)>' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/friendly_errors.rb:3:in with_friendly_errors'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/bin/bundle:20:in
<top (required)>' from C:/Ruby193/bin/bundle:23:inload'
from C:/Ruby193/bin/bundle:23:in <main>' PS C:\Recondo\projects\svn\reco\services\portal\trunk\portal-trunk\portal_builder> bundle exec .\bin\portal_builder --help bundler: command not found: .\bin\portal_builder Install missing gem executables withbundle installPS C:\Recondo\projects\svn\reco\services\portal\trunk\portal-trunk\portal_builder> bin/portal_builder PS C:\Recondo\projects\svn\reco\services\portal\trunk\portal-trunk\portal_builder> ruby bin/portal_builder C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:inrequire':
cannot load such file -- portal_builder.rb (LoadError)
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in
require' from bin/portal_builder:5:in

'
PS
C:\Recondo\projects\svn\reco\services\portal\trunk\portal-trunk\portal_builder>
bundle exec bin/portal_builder
Unfortunately, a fatal error has occurred. Please see the Bundler
troubleshooting documentation at http://bit.ly/bundler-issues. Thanks!
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/cli.rb:503:in
exec': Exec format error - bin/portal_builder (Errno::ENOEXEC) from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/cli.rb:503:in exec'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor/task.rb:27:in
run' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor/invocation.rb:120:in invoke_task'
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor.rb:344:in
dispatch' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/vendor/thor/base.rb:434:in start'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/bin/bundle:20:in
block in <top (required)>' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/friendly_errors.rb:3:in with_friendly_errors'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/bin/bundle:20:in
<top (required)>' from C:/Ruby193/bin/bundle:23:inload'
from C:/Ruby193/bin/bundle:23:in `'

If I include --help at the end of that I get an even stranger message.
bundle exec bin/portal_builder --help
bundler: command not found: bin/portal_builder
Install missing gem executables with bundle install

โ€”
Reply to this email directly or view it on GitHubhttps://github.com//issues/63
.

I'm pretty sure I didn't generate binstubs. Where do I add that RUBYLIB line? I tried adding rubygems at the top of portal_builder and that didn't work either. I actually don't understand entirely what is even going on here. So is the portal_builder file a gem?

Sorry, let me explain a bit more.

in UNIX, if you do something like:

RUBYLIB=lib bin/portal_builder

It will set the environment variable RUBYLIB to lib for that single
command execution. RUBYLIB is a variable that contains "extra" paths
ruby will look for when you require something. bundler is supposed to set
that for you when you do bundle exec.

I'm not sure how to do that on the Windows command line, but I think it's
something like set RUBYLIB=lib or even set RUBYLIB=full/path/to/your/lib.

As to the gem comment, the entire project Methadone generates is designed
to be created and distributed as a gem. Theoretically, if you built the
gem (e.g. with rake gem), it will create a .gem file in pkg/ that you
could then install with gem install pkg/porta_builder-0.0.1.gem (or
whatever it's named). When you do that, the command line app
portal_builder should be in your path and it should work (i.e. RubyGems
will have set up all the load path stuff).

It's possible this stuff works differently on Windows.

One other thing you can try is to manipulate the load path in code. To do
that, open up your bin/portal_builder and add this line right before the
first require:

$: << File.expand_path(File.join(File.dirname(__FILE__),'..','lib')

If you haven't seen this before, $: is the variable in Ruby that holds
the load path (it's an array of strings). __FILE__ is path to the
current file ruby is executing, so dirname gets the directory that's in,
and .., then lib gets you to your lib directory, where
portal_builder.rb is hopefully waiting for you. This should also allow
that require to work.

Let me know if all that makes sense?

Dave


Buy My Book: http://www.awesomecommandlineapps.com
My Blog: http://www.naildrivin5.com/blog
Fork me on Github: http://davetron5000.github.com

On Fri, Apr 19, 2013 at 1:14 PM, Tyler Thrailkill
notifications@github.comwrote:

I'm pretty sure I didn't generate binstubs. Where do I add that RUBYLIB
line? I tried adding rubygems at the top of portal_builder and that didn't
work either. I actually don't understand entirely what is even going on
here. So is the portal_builder file a gem?

โ€”
Reply to this email directly or view it on GitHubhttps://github.com//issues/63#issuecomment-16665624
.

Ah ok, so I have to have my RUBYLIB env variable set to '.' for another project I have. I tried setting the RUBYLIB to both just lib, and the full path. Didn't work. Tried using rake gem.

 rake gem
rake aborted!
Don't know how to build task 'gem'

Tried adding the ruby $: << line in portal_builder. Still didn't work. I'm at a loss :
Thankfully I installed a Mac OS X vm in virtualbox last night so I might try it on there this weekend.

Darn, I'm sorry about all this. I wish I had a windows box to try this
stuff out on, but it seems Window is a second-class citizen on Ruby :(

Dave


Buy My Book: http://www.awesomecommandlineapps.com
My Blog: http://www.naildrivin5.com/blog
Fork me on Github: http://davetron5000.github.com

On Fri, Apr 19, 2013 at 1:58 PM, Tyler Thrailkill
notifications@github.comwrote:

Ah ok, so I have to have my RUBYLIB env variable set to '.' for another
project I have. I tried setting the RUBYLIB to both just lib, and the full
path. Didn't work. Tried using rake gem.

rake gem
rake aborted!
Don't know how to build task 'gem'

Tried adding the ruby $: << line in portal_builder. Still didn't work. I'm
at a loss :
Thankfully I installed a Mac OS X vm in virtualbox last night so I might
try it on there this weekend.

โ€”
Reply to this email directly or view it on GitHubhttps://github.com//issues/63#issuecomment-16669232
.

Yes it is very much so. :\

I'm late to the party, but try this instead: bundle exec ruby bin/portal_builder

On Windows, specify the ruby command when running ruby programs.

jppunnett- Yep that works.

Makes sense when you think about it. Windows doesn't know to execute the file as a ruby file, since it doesn't read the sha-bang (!#) directive at the top of the file, but rather relies on file extensions that these 'binaries' don't have. +1 for the solution

I ran into the same problem here - ruby 1.9.3-p545 and Windows 7 (32-bit). Putting "ruby" in there fixed it for me. In hindsight, it's pretty obvious - if bundler's error message so obtuse it would've been easy to see where the problem was.

Windows will (if you have it configured to) run files with a .rb extension with ruby. Renaming the bin/app file to bin/app.rb doesn't work, though. Not a big deal, just FWIW.

Man, this is weird. I was just going to update this last night saying that including the ruby works (I forgot to do it like last year). I guess I should close the issue now. Note that this issue crops up in Dave's book during the testing with Aruba section. I'll mention it here because it was a major problem I encountered last night. Use bundler.bat exec ruby ../../bin/#{app_name} help during the first part of chapter 8.