# engine.ExecuteFile gives errors

**URL:** <https://www.ruby-forum.com/t/engine-executefile-gives-errors/169962>\
**Category:** IronRuby\
**Created:** [June 10, 2009, 6:55pm UTC](https://www.ruby-forum.com/t/engine-executefile-gives-errors/169962 "2009-06-10T18:55:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 10, 2009, 6:55pm UTC](https://www.ruby-forum.com/t/engine-executefile-gives-errors/169962/1 "2009-06-10T18:55:09Z")

</div>

I am using the following code to execute a Ruby file from C# but it  
gives me the error:

var runtime = IronRuby.Ruby.CreateRuntime();  
var engine = runtime.GetEngine(“rb”);

```
        engine.ExecuteFile("../../HelloWorld.rb");

```

And here is the error:

Unhandled Exception: Microsoft.Scripting.SyntaxErrorException: syntax  
error, une  
xpected END, expecting END\_OF\_FILE  
at Microsoft.Scripting.ErrorSink.Add(SourceUnit source, String  
message, Sourc  
eSpan span, Int32 errorCode, Severity severity)  
at Microsoft.Scripting.ErrorCounter.Add(SourceUnit source, String  
message, So  
urceSpan span, Int32 errorCode, Severity severity)  
at IronRuby.Compiler.Parser.ReportSyntaxError(String message)  
at IronRuby.Compiler.Parser.ErrorRecovery()  
at IronRuby.Compiler.Parser.Parse()  
at IronRuby.Compiler.Parser.Parse(SourceUnit sourceUnit,  
RubyCompilerOptions  
options, ErrorSink errorSink)  
at IronRuby.Runtime.RubyContext.ParseSourceCode[T](SourceUnit  
sourceUnit, Rub  
yCompilerOptions options, ErrorSink errorSink)  
at IronRuby.Runtime.RubyContext.CompileSourceCode(SourceUnit  
sourceUnit, Comp  
ilerOptions options, ErrorSink errorSink)  
at Microsoft.Scripting.SourceUnit.Compile(CompilerOptions options,  
ErrorSink  
errorSink)

And here is the Ruby file:

class Person

def foo()  
puts ‘hello world’  
end

end

person = Person.new()  
person.foo()

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 12, 2009, 7:42pm UTC](https://www.ruby-forum.com/t/engine-executefile-gives-errors/169962/2 "2009-06-12T19:42:00Z")

</div>

Is it possible that you’ve saved the file as UTF-8 or Unicode?

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 12, 2009, 7:52pm UTC](https://www.ruby-forum.com/t/engine-executefile-gives-errors/169962/3 "2009-06-12T19:52:26Z")

</div>

Curt H. wrote:

> Is it possible that you’ve saved the file as UTF-8 or Unicode?

Well I just created a text file with “.rb” extension.

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 12, 2009, 8:11pm UTC](https://www.ruby-forum.com/t/engine-executefile-gives-errors/169962/4 "2009-06-12T20:11:30Z")

</div>

That is a problem because visual studio adds UTF-8 encoding to that  
file.  
I created one file in notepad and made a template from that file and I  
use  
that template to create new ruby files in visual studio.

* * *

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([http://manning.com/carrero](http://manning.com/carrero))

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 12, 2009, 8:12pm UTC](https://www.ruby-forum.com/t/engine-executefile-gives-errors/169962/5 "2009-06-12T20:12:42Z")

</div>

Here’s the easiest way I know how to check:

1. Open the file in Notepad
2. Choose “File | Save As”
3. Look at the value for “Encoding”. If it’s anything other than “ANSI”,  
change the encoding to ANSI, save the file and try again.

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [June 12, 2009, 8:14pm UTC](https://www.ruby-forum.com/t/engine-executefile-gives-errors/169962/6 "2009-06-12T20:14:56Z")

</div>

Awesome guys I got it working!

Thanks a million! 🙂
