Eelco Henderichs
2009-Oct-06 20:47 UTC
[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/.
Jimmy Schementi
2009-Oct-06 21:06 UTC
[Ironruby-core] C# running ruby scripts give error: no such file to load
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-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 > 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 at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core
Eelco Henderichs
2009-Oct-07 10:56 UTC
[Ironruby-core] C# running ruby scripts give error: no such file to load
Thanks, I wasn''t aware I should set all loadpaths from within the application to use the ''win32ole''. Now it finds the win32ole, but it gives an error when trying to execute the require. On require ''win32ole'' the following error is displayed. The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018) I have no idea what this means. -- Posted via http://www.ruby-forum.com/.
Eelco Henderichs
2009-Oct-07 13:46 UTC
[Ironruby-core] C# running ruby scripts give error: no such file to load
Seemed the script required the ''win32ole'' from Ruby and not IronRuby. Using the IronRuby win32ole class does not give any errors. Eelco Henderichs wrote:> Thanks, I wasn''t aware I should set all loadpaths from within the > application to use the ''win32ole''. > > Now it finds the win32ole, but it gives an error when trying to execute > the require. > > On require ''win32ole'' the following error is displayed. > The module was expected to contain an assembly manifest. (Exception from > HRESULT: 0x80131018) > > I have no idea what this means.-- Posted via http://www.ruby-forum.com/.