[IronPython] retreiving output

Larry O'Brien lobrien at knowing.net
Tue Jan 25 22:20:42 CET 2005

I sent the original of this offlist...

What I did in Pynk (article and source at
http://www.devx.com/TabletPC/Article/26666) was create a buffer class and
redirect Python's stdout to it:

	q = new OutputQueue();			
	sys.stdout = q.pythonOut;


	public class OutputQueue
		MemoryStream outStr = new MemoryStream(1024);
		StreamReader outRdr;
		public PythonFile pythonOut;

		public OutputQueue()
			outRdr = new StreamReader(outStr);
			pythonOut = new PythonFile(outStr, "rw", false);

		public string ReadToEnd()
			//Reset and read
			outStr.Position = 0;
			string retval = outRdr.ReadToEnd();

			//Null it out
			outStr.Position = 0;
			byte[] nulls = new byte[retval.Length];

			//Reset for writing
			outStr.Position = 0;
			return retval;


More information about the Ironpython-users mailing list