[Ironruby-core] C# running ruby scripts give error: no such file to load
Jimmy.Schementi at microsoft.com
Tue Oct 6 17:06:22 EDT 2009
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:
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:
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).
> -----Original Message-----
> From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-
> bounces at rubyforge.org] On Behalf Of Eelco Henderichs
> Sent: Tuesday, October 06, 2009 1:47 PM
> To: ironruby-core at rubyforge.org
> Subject: [Ironruby-core] C# running ruby scripts give error: no such file to
> 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:
> Testscripts located in:
> These testscripts uses custom made libraries located in:
> But also they use standard ruby libraries located in:
> So the top of the testscripts can look someting like:
> require '../Common/LibTestCase1'
> require '../Common/LibTestCase2'
> 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 =
> 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 at rubyforge.org
More information about the Ironruby-core