Running some shell scripts that run Python scripts, I get re-ordering of stdout lines when redirecting to tee or a file.
For example, if I run the shell script and get output to my stdout, my output looks like:
Line1: Starting X Line2: Output of X Line3: Starting Y Line4: Output of Y
But If I run the same script and redirect output to file, or use tee, print statements from the underlying Python script will be printed at the very end of execution.
Line1: Output of X Line2: Output of Y Line3: Starting X Line4: Starting Y
Is there anything I can do to avoid this?