I am using ProcessStartInfo in C# to run my python script. But i want to know what percentage the python script has processed.
I am using below code. Python:
import time
if __name__ == '__main__':
for i in range(100):
#do something
time.sleep(5)
print(i+1,"%")
C#:
private void run_cmd(string cmd, string args)
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = cmd;
start.Arguments = args;
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Console.Write(result);
// do something to show percentage
}
}
}
But I received everything python printed at once like (1%, 2%,...100%).
How can I received the commandprompt output step by step.
P/s: I tried to edit RedirectStandardOutput = false to get it step by step but I have an error in C# code.