-1

I have a ruby script with following content:

#!/data1/thirdparty/ruby/bin/ruby -I/data1/thirdparty/ruby/lib/ruby/2.0.0 -I/data1/thirdparty/ruby/lib/ruby/gems/2.0.0/gems/ruby-net-ldap-0.0.4 -I/data1/thirdparty/ruby/lib/ruby/site_ruby/2.0.0 -I/data1/thirdparty/ruby/lib/ruby/2.0.0/i686-linux

When I ran the script it throws the following error:

<internal:gem_prelude>:1:in `require': cannot load such file -- rubygems.rb (LoadError)
        from <internal:gem_prelude>:1:in `<compiled>'

I took an strace of the program and found this in the strace:

open("/data1/thirdparty/ruby/lib/ruby/2.0.0 -I/data1/thirdparty/enc/encdb.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)

So it seems like ruby is not able to handle -I properly because it is including it in the file path itself. How can I force the script to use -I as an include path directive?

Amit Bhaira
  • 1,687
  • 6
  • 18
  • 31
  • This has nothing to do with Ruby. It is about how to use your operating system properly, and thus belongs on [SuperUser](http://superuser.com/). It's basically just a variation of "how do I call programs in my shell". – Jörg W Mittag Oct 05 '15 at 06:56
  • http://stackoverflow.com/a/4304187/2988 – Jörg W Mittag Oct 05 '15 at 10:25

2 Answers2

1

I would work with rvm and bundler. You can then call your script with a rvm-wrapper (for example if run in a cron job), or with bundle exec for development. You will need to have your *.gemspec well configured (for an example run bundle new mygem and look at mygem.gemspec).

The other possibility would be to write a shell script including

/data1/thirdparty/ruby/bin/ruby -I/data1/thirdparty/ruby/lib/ruby/2.0.0 -I/data1/thirdparty/ruby/lib/ruby/gems/2.0.0/gems/ruby-net-ldap-0.0.4 -I/data1/thirdparty/ruby/lib/ruby/site_ruby/2.0.0 -I/data1/thirdparty/ruby/lib/ruby/2.0.0/i686-linux <yourfile.rb>

.

Btw. the #! line is called a shebang or hashbang, in case you want to research what happens.

Community
  • 1
  • 1
Felix
  • 4,510
  • 2
  • 31
  • 46
1

Try this one:

#!/bin/bash
exec /data1/thirdparty/ruby/bin/ruby -I/data1/thirdparty/ruby/lib/ruby/2.0.0 -I/data1/thirdparty/ruby/lib/ruby/gems/2.0.0/gems/ruby-net-ldap-0.0.4 -I/data1/thirdparty/ruby/lib/ruby/site_ruby/2.0.0 -I/data1/thirdparty/ruby/lib/ruby/2.0.0/i686-linux -x "$0" "$@"

#!ruby
p "this is my ruby code"
Shriram V
  • 1,500
  • 2
  • 11
  • 20