[IronPython] Hosting question

Ryan Dawson rdawson at exchange.microsoft.com
Fri Jul 28 02:25:25 CEST 2006

Hmm, I suspect this has something to do with your handling of the stream.  Below is a little pure IronPython snippet that I'm using to test.

If you'd like to post your code for PythonOutputStream I'd be happy to take a look.  Hope this helps...

from IronPython.Hosting import PythonEngine
from System.IO import MemoryStream
from System.IO import StreamReader
from System.Text import ASCIIEncoding

class MyStream(MemoryStream):
        def Write(self,buffer,offset,count):
                        print 'Writing "%s"' % ASCIIEncoding().GetString(buffer,offset,count)

s = MyStream()

pe = PythonEngine()

pe.Execute("print 3")

text = StreamReader(s).ReadToEnd()
print 'Final text = "%s"' % text

Output when run:
Writing "3"
Writing "
Final text = "3

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Slide
Sent: Thursday, July 27, 2006 2:47 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Hosting question

On 7/27/06, Ryan Dawson <rdawson at exchange.microsoft.com> wrote:
> Right, the Evaluate* methods are just for expressions.
> Locally, I'm not seeing extra new lines being appended to the end of output.  That's not to say we don't have a bug here, we might.  Can you provide some more information?
> This happens on a simple "print 3"?  We should be writing "3"+Environment.NewLine.  How are you reading from the memory stream?
> Thanks,
>         -Ryan

I created a class I called PythonOutputStream that inherits from Stream, internally it has a MemoryStream. I set the stdout of the PythonEngine to one of these. In the Flush method of the PythonOutputStream, I grab all the data from the stream and then fire an event with the text from the stream and reset it. I see the flush being called several times after the initial output of "3" in the example of "print 3". I tried moving the output of data into the Write method, but the same thing occurs, I still get a couple "\r\n"s after the initial output.


users mailing list
users at lists.ironpython.com

More information about the Ironpython-users mailing list