Following this problem I couldn't find any solution to,
I'm now trying to run a python script from C#, with an infinite loop inside, printing a result at each iteration. And I want to get each result in C#.
So this is my python script :
#!/usr/bin/env python3
import time
while(True) :
print(1)
time.sleep(0.5)
And here is my C# program :
static void Main()
{
using (Process myProcess = new Process())
{
var errors = "";
var results = "";
myProcess.StartInfo.FileName = "python";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.Arguments = "../../test.py";
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.Start();
StreamReader outputStream = myProcess.StandardOutput;
while(true)
{
results = outputStream.ReadToEnd();
Console.WriteLine("Results:");
Console.WriteLine(results);
outputStream.DiscardBufferedData();
}
}
}
And obviously, nothing gets printed to the console.
But I have no clue how I'm supposed to change my code to get back and use the "1"s.
It sounds like it should be quite easy to do, yet I've been stuck trying to make it work for some hours now. I'm currently thinking about sending my python script's results to a text file, and reading back the text file in C#. But I'd rather not have to do this, cause it looks ugly and will cause (avoidable, yet annoying) conflicts.
So, is there something I can do ?
Thanks for your help,
Astrosias.