0

I can run python script from c# using following code:

const string python = @"C:\path\to\python.exe";
const string myPythonApp = @"C:\path\to\TestFile.py";

var myProcessStartInfo = new ProcessStartInfo(python)
{
    UseShellExecute = false,
    RedirectStandardOutput = true,
    Arguments = myPythonApp + " " + args
};

var myProcess = new Process();
myProcess.StartInfo = myProcessStartInfo;

myProcess.Start();
var myStreamReader = myProcess.StandardOutput;
var result = myStreamReader.ReadLine();

Work well, but start new process is very slow (need to run milions of iterations). I want to try start python proces once and then pass arguments... Pseudo code:

C#:

myProcess.Start();
var myStreamReader = myProcess.StandardOutput;
for (var i = 0; i < 100000; i++)
{
    // here I want to pass new arguments to cmd
    var result = myStreamReader.ReadLine();
}

Python:

def do_something(args):
    # do something
    pass    

while (True):
    args = input()
    print(do_something(args))

Some ideas? (Iron Python is bad, can not import packages).

franta96
  • 75
  • 5

0 Answers0