Hello all,

I'm diverting the standard ouput and standard error streams on a Python engine. I would like to provide a Stream that executes a callback on every write (rather than just collecting output as most of the examples show).

Inheriting from 'Stream' is easy but requires implementing a tedious number of methods and properties. Inheriting from 'MemoryStream' and only overriding 'Write' (plus the constructor) works fine. I'm wondering if it is 'correct'? It is probably an abuse of MemoryStream - can this approach fail?

internal class PythonStream: MemoryStream
{
   TextBox _output;
   public PythonStream(TextBox textbox)
   {
       _output = textbox;
   }

   public override void Write(byte[] buffer, int offset, int count)
   {
       _output.AppendText(Encoding.UTF8.GetString(buffer, offset, count));
   }
}



--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/
http://www.trypython.org/
http://www.ironpython.info/
http://www.theotherdelia.co.uk/
http://www.resolverhacks.net/

_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to