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.
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)
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
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With