Catch Shell output from Python script

I have a Python script that prints numbers to the Shell, for example: 1/20 or 5/50, and I would like to be able to catch these numbers from the Shell.

I use a Timer that executes each 500 ms Shell1.Poll inside the Action event, and I use the DataAvailable event of the Shell1 to catch the output with Me.ReadAll. Unfortunately, this is not working. I don’t get any output while the Python script is running.

Shell1.Execute(" C:\list.txt") is called inside a button Pressed event. Before Shell1.Execute, I start the Timer with Timer1.RunMode = Timer.RunModes.Multiple.

My goal is to use the numbers from the output to update a progress bar in my application. 1/20 means for example 5% progressed, 5/50 means 10% progressed.

What am I doing wrong?

I have found the solution for my problem.

In Python you need to use print(print_str, flush=True) whenever you use print(), then it will trigger the DataAvailable event in the Shell object.

“flush” is set to false by default when you use print().