+5  A: 

You can set a stream and a textwriter directly from c#:

engine.Runtime.IO.SetOutput(stream, txtWriter);
engine.Runtime.IO.SetErrorOutput(stream, txtWriter);

To redirect the output for example you could override TextWriter class with a new one writing on your textbox.


e.g.

in my application I did an override of StreamWriter class that rises events when something is written on the stream (here just a part of the code):

public class MyEvtArgs<T> : EventArgs
{
    public T Value
    {
        get;
        private set;
    }
    public MyEvtArgs(T value)
    {
        this.Value = value;
    }
}


public class EventRaisingStreamWriter : StreamWriter
{
    #region Event
    public event EventHandler<MyEvtArgs<string>> StringWritten;
    #endregion

    #region CTOR
    public EventRaisingStreamWriter(Stream s):base(s)
    { }
    #endregion

    #region Private Methods
    private void LaunchEvent(string txtWritten)
    {
        if (StringWritten != null)
        {
            StringWritten(this, new NewValueEventArgs<string>(txtWritten));
        }
    }
    #endregion


    #region Overrides

    public override void Write(string value)
    {
        base.Write(value);
        LaunchEvent(value);
    }
    public override void Write(bool value)
    {
        base.Write(value);
        LaunchEvent(value.ToString());
    }
    // here override all writing methods...

    #endregion
}

Then in your application you should just do something like:

    MemoryStream ms = new MemoryStream();

    outputWr = new EventRaisingStreamWriter(ms);
    outputWr.StringWritten += new EventHandler<MyEvtArgs<string>>(sWr_StringWritten);

    engine.IO.SetOutput(ms, errorWr);



    void sWr_StringWritten(object sender, MyEvtArgs<string> e)
    {
        textBox1.Text += s.Value;
    }
digEmAll
Check my edits ;)
digEmAll
Thanks a lot, it's OK!
Begtostudy