Following answer from this question I’ve found that using dir > a.txt 2>&1
to output stdout and stderr to a file might be unreliable as stdout and stderr appear to get unsynced sometimes. The result in the file differs from what I see when running the command directly in the console — e.g. stderr output can appear before stdout or after, seemingly at random.
Is there a more reliable way to redirect both outputs to a file on Windows?
I’ve found if it’s just a python script then running py -u test.py > a.txt 2>&1
helps (it “forces the stdout and stderr streams to be unbuffered. This option has no effect on the stdin stream.”)