I'd like to produce a readable HTML report of a process run. Towards that end, I'd like to track both stdout and stderr, and output them interleaved, yet distinguished - for example, the log will show them both combined according to the order they were emitted, but with stdout in black and stderr in bold red.
I can readily see a solution that will keep them distinguished: just redirect each to subprocess.PIPE. Of course, then they can't be recombined in order. It's also easy to unify them in order: just redirect stderr to subprocess.STDOUT. However, then they will be indistinguishable.
Thus getting the outputs to be either distinguished or combined in order is straightforward, but getting both is not.
What's the way to do that in Python?