# Executing an Ironruby file from a console app

**URL:** <https://www.ruby-forum.com/t/executing-an-ironruby-file-from-a-console-app/163549>\
**Category:** IronRuby\
**Created:** [March 21, 2009, 9:33pm UTC](https://www.ruby-forum.com/t/executing-an-ironruby-file-from-a-console-app/163549 "2009-03-21T21:33:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bbe5ce/32.png) [@paul](https://www.ruby-forum.com/u/paul)\
**Post date:** [March 21, 2009, 9:33pm UTC](https://www.ruby-forum.com/t/executing-an-ironruby-file-from-a-console-app/163549/1 "2009-03-21T21:33:41Z")

</div>

Hi all,

I have the following ruby code which runs in a console application:

require File.dirname( **FILE** ) + ‘/lib/horn’  
require File.dirname( **FILE** ) + ‘/lib/dsl’

The file is named hornbuild.rb.

The main ruby file has a require directive for this hornbuild.rb like  
so:

require ‘hornbuild’

I then execute the ruby file like this:

var engine = Ruby.CreateEngine();  
engine.ExecuteFile(buildFilePath);

The problem is that I can only get this scenario to work by copying the  
hornbuild.rb file and lib folder into the bin directory of the console  
application.

Can I not put these files in the gems folder or something so they are  
globally accessible.

If so, how can I achieve this?

Cheers

Paul

---

<div class="post-metadata">

**Author:** ![paul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bbe5ce/32.png) [@paul](https://www.ruby-forum.com/u/paul)\
**Post date:** [March 21, 2009, 11:50pm UTC](https://www.ruby-forum.com/t/executing-an-ironruby-file-from-a-console-app/163549/2 "2009-03-21T23:50:53Z")

</div>

You can set load paths.

var engine = Ruby.CreateEngine();  
var context = Ruby.GetExecutionContext(engine);  
context.Loader.SetPaths(“C:\ironruby\lib”);

---

<div class="post-metadata">

**Author:** ![paul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bbe5ce/32.png) [@paul](https://www.ruby-forum.com/u/paul)\
**Post date:** [March 22, 2009, 4:51am UTC](https://www.ruby-forum.com/t/executing-an-ironruby-file-from-a-console-app/163549/3 "2009-03-22T04:51:29Z")

</div>

ScriptEngine.SetSearchPaths should also work.

Tomas

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Ivan Porto  
Carrero  
Sent: Saturday, March 21, 2009 3:41 PM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Executing an Ironruby file from a console  
app.

You can set load paths.

var engine = Ruby.CreateEngine();  
var context = Ruby.GetExecutionContext(engine);  
context.Loader.SetPaths(“C:\ironruby\lib”);

On Sat, Mar 21, 2009 at 9:33 PM, Paul Cowan  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:  
Hi all,

I have the following ruby code which runs in a console application:

require File.dirname( **FILE** ) + ‘/lib/horn’  
require File.dirname( **FILE** ) + ‘/lib/dsl’

The file is named hornbuild.rb.

The main ruby file has a require directive for this hornbuild.rb like  
so:

require ‘hornbuild’

I then execute the ruby file like this:

var engine = Ruby.CreateEngine();  
engine.ExecuteFile(buildFilePath);

The problem is that I can only get this scenario to work by copying the  
hornbuild.rb file and lib folder into the bin directory of the console  
application.

Can I not put these files in the gems folder or something so they are  
globally accessible.

If so, how can I achieve this?

Cheers

## Paul

Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

* * *

Ironruby-core mailing list  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)
