From: Jason Roelofs Date: 2007-08-10T23:36:20+09:00 Subject: Re: ENV['LD_LIBRARY_PATH'] not changing env ------=_Part_10514_12448622.1186756584907 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 8/10/07, TDR wrote: > > Ruby 1.8.6 on solaris 9. > > I am a newbie. > I need to set LD_LIBRARY_PATH within my script as follows: > > ENV['LD_LIBRARY_PATH'] = '/usr/local/mysql/lib/mysql:/usr/local/ > easysoft/unixODBC/lib:/usr > /local/easysoft/lib' > > but it doesn't seem to be "taking". I get the error I would expect to > get when LD_LIBRARY_PATH is not set: > > s00c166.ssa.gov# ruby -r debug process_ond.rb > Debug.rb > Emacs support available. > > process_ond.rb:29:def lookup_cid(off_id) > (rdb:1) b 95 > Set breakpoint 1 at process_ond.rb:95 > (rdb:1) c > Breakpoint 1, toplevel at process_ond.rb:95 > process_ond.rb:95:ENV['LD_LIBRARY_PATH'] = '/usr/local/mysql/lib/ > mysql:/usr/local/easysoft/unixODBC/lib:/usr/local/easysoft/lib' > (rdb:1) n > process_ond.rb:99:$dbh_ditm = DBI.connect("DBI:Mysql:ditm:localhost", > "ditmusr", "xxxxxx") > (rdb:1) n > /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:344: `Could not load driver > (ld.so.1: ruby: fatal: libmysqlclient.so.15: open failed: No such file > or directory - /usr/local/lib/ruby/site_ruby/1.8/sparc-solaris2.9/ > mysql.so)' (DBI::InterfaceError) > from /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:344:in > `load_driver' > from /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:227:in > `_get_full_driver' > from /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:213:in `connect' > from process_ond.rb:99 > /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:344: raise > InterfaceError, "Could not load driver (#{$!.message})" > (rdb:1) > > But when I set LD_LIBRARY_PATH in my shell, prior to running the > script, I don't get this error: > > s00c166.ssa.gov# setenv LD_LIBRARY_PATH '/usr/local/mysql/lib/mysql:/ > usr/local/easysoft/unixODBC/lib:/usr/local/easysoft/lib' > s00c166.ssa.gov# ruby -r debug > process_ond.rb Debug.rb > Emacs support available. > > process_ond.rb:29:def lookup_cid(off_id) > (rdb:1) b 99 > Set breakpoint 1 at process_ond.rb:99 > (rdb:1) c > Breakpoint 1, toplevel at process_ond.rb:99 > process_ond.rb:99:$dbh_ditm = DBI.connect("DBI:Mysql:ditm:localhost", > "ditmusr", "xxxxxx") > (rdb:1) n > > What am I doing wrong here? > > TDR Just setting LD_LIBRARY_PATH in your Ruby script won't help, as it doesn't update the environment of the current runner (see it as nested environments). So what you're doing is setting the child's environment, but it's the parent that goes out and loads up libraries like mysql.so. So what you need to do is re-execute your process after setting LD_LIBRARY_PATH; something like this: unless ENV["LD_LIBRARY_PATH"].grep /easysoft\/unixODBC/ ENV['LD_LIBRARY_PATH'] = '/usr/local/mysql/lib/mysql:/usr/local/easysoft/unixODBC/lib:/usr/local/easysoft/lib'' exec(ARGV) end I don't think the above is exactly right, maybe you need *ARGV, but it gets the point across. You need to restart the script with the appropriate environment settings. Jason ------=_Part_10514_12448622.1186756584907--