Passing data to and fro during run time between C# Winform and Python Script, using Ironpython

286 Views Asked by At

When I click the button On winform, this get executed:

using (var outStream = new ScriptOutputStream(win.txtOutput))
{
    ExecuteScript(outStream);
}

This is the function to run the script.

private void ExecuteScript(Stream outputStream)
{
    var ipy = IronPython.Hosting.Python.CreateRuntime(); 
    engine = IronPython.Hosting.Python.GetEngine(ipy);
    engine.Runtime.IO.SetOutput(outputStream, Encoding.GetEncoding(1252));
    scope = engine.CreateScope();
    engine.ExecuteFile(@"trial.py", scope);       
}

ScriptOutputStream() is my function that will create an object of the textbox and just write from the buffer into it. No problem there. This outputs the Python Console into the text box.

How do I pass data from another button click, to trial.py, and once trial.py runs, read input back from it. The python thread must also be running on it's own thread simultaneously, and be listening for inputs.

0

There are 0 best solutions below