File.dirname(__FILE__) will give you the directory of the current file, so you can place this in-front of your requires to make sure they are always relative to the current file, rather than the current directory:
Testscript1.rb: require File.dirname(__FILE__) + '/../Common/LibTestCase1' require File.dirname(__FILE__) + '/../Common/LibTestCase2' You could also add "File.dirname(__FILE__) + '/../Common/'" to the path like this: $: << File.dirname(__FILE__) + '/../Common/' So then requires can just be: require 'LibTestCase1' require 'LibTestCase2' These are just issues related to how Ruby deals with relative paths and the current directory, regardless of whether you ran the code from C# or not. However, it should find win32ole just fine ... do you have an app.config for your C# app which sets the load path (see ir.exe.config for example). ~js > -----Original Message----- > From: ironruby-core-boun...@rubyforge.org [mailto:ironruby-core- > boun...@rubyforge.org] On Behalf Of Eelco Henderichs > Sent: Tuesday, October 06, 2009 1:47 PM > To: ironruby-core@rubyforge.org > Subject: [Ironruby-core] C# running ruby scripts give error: no such file to > load > > Hello ironruby user, > > Here I am with another question. This is a problem I ran in a few weeks ago, > found a workaround, but this workaround is far from perfect. > > As some might already know, I am building an C# application and am using > ironruby to run rubyscripts. > > Application located in: > D:\app\bin > > Testscripts located in: > K:\Testscripts\Specific > > These testscripts uses custom made libraries located in: > K:\Testscripts\Common > > But also they use standard ruby libraries located in: > C:\Ruby\lib\... > > So the top of the testscripts can look someting like: > > Testscript1.rb > require '../Common/LibTestCase1' > require '../Common/LibTestCase2' > ... > or > > Testscript2.rb > require 'win32ole' > require 'ftools' > ... > > Now the problem: > > Running these these testscripts from the C# application (using e.g. > engine.ExecuteFile) results in the error: no such file to load -- > '../Common/LibTestCase1' or 'win32ole' or whatever file is required. > It seems the scripts (or application) is trying to located the file relative > to the > path the application is located. > > This leads me to the workaround. Before running the testscript from the > application change the current directory of the application to the location of > the testscripts (using Environment.CurrentDirectory = > K:\Testscripts\Specific) > > Since testscripts can be located deeper in the directory stucture I need to > keep changing the current directory of the application. You'll understand that > this is a pretty sucky workaround. > > I have tried using SetLoadPath to include the directories where the required > files can be found, but this still gives the same error. > > So I am looking for a more flexibel solution for this problem. Hopefully > someone here provide information to stear me in the correct direction. > > Thanks in advance > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core@rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core@rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core