Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Streaming Ironpython output to my editor

Tags:

ironpython

We embed ironpython in our app sob that scripts can be executed in the context of our application.

I use Python.CreateEngine() and ScriptScope.Execute() to execute python scripts.

We have out own editor(written in C#) that can load ironpython scripts and run it.

There are 2 problems I need to solve.

  1. If I have a print statement in ironpython script, how can i show it my editor(how will I tell python engine to redirect output to some handler in my C# code)

  2. I plan to use unittest.py for running unittest. When I run the following runner = unittest.TextTestRunner() runner.run(testsuite)

the output is redirected to standard output but need a way for it to be redirected to my C# editor output window so that user can see the results. This question might be related to 1

Any help is appreciated G

like image 765
Ganesh Avatar asked Dec 23 '22 06:12

Ganesh


1 Answers

You can provide a custom Stream or TextWriter which will be used for all output. You can provide those by using one of the ScriptRuntime.IO.SetOutput overloads. Your implementation of Stream or TextWriter should receive the strings and then output them to your editor window (potentially marshalling back onto the UI thread if you're running the script on a 2ndary execution thread).

like image 59
Dino Viehland Avatar answered Dec 27 '22 09:12

Dino Viehland