How can I redirect the stdout of ironpython in C#?

Posted by Begtostudy on Stack Overflow See other posts from Stack Overflow or by Begtostudy
Published on 2010-06-16T15:56:27Z Indexed on 2010/06/16 16:42 UTC
Read the original article Hit count: 191

Filed under:
|
|
|

  public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

    private void button3_Click(object sender, EventArgs e)
    {
        try
        {
            var strExpression = @"

import sys sys.stdout=my.write print 'ABC' "; var engine = Python.CreateEngine(); var scope = engine.CreateScope(); var sourceCode = engine.CreateScriptSourceFromString(strExpression); scope.SetVariable("my", this); var actual = sourceCode.Execute(scope); textBox1.Text += actual; } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } }

public void write(string s) { textBox1.Text += s; } }<code>

But Exception says there is not write.

Where is wrong? Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about redirect