我有一个包含以下内容的ruby脚本:
putMVar
当我运行脚本时,它会抛出以下错误:
#!/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
我接受了该程序的一部分并在strace中找到了这个:
<internal:gem_prelude>:1:in `require': cannot load such file -- rubygems.rb (LoadError)
from <internal:gem_prelude>:1:in `<compiled>'
因此,似乎ruby无法正确处理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)
,因为它将它包含在文件路径本身中。如何强制脚本使用-I
作为包含路径指令?
答案 0 :(得分:1)
我会使用rvm和bundler。然后,您可以使用rvm-wrapper调用脚本(例如,如果在cron作业中运行),或使用bundle exec
进行开发。您需要配置好*.gemspec
(例如,运行bundle new mygem
并查看mygem.gemspec
)。
另一种可能性是编写包含
的shell脚本/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>
顺便说一下。 #!
行被称为shebang或hashbang,以防你想研究会发生什么。
答案 1 :(得分:1)
试试这个:
#!/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"