Fix Interactive container hangs when redirecting stdout

Fixes #6509
Closes #7658

This is a rebase of #7658 + tests. Thanks @VojtechVitek !

I even tested the `events` test with one commit before the #5979 PR and it failed. So all 3 are needed.

Ping @erikh @jfrazelle
These are not exported members, so I don't see why it's not a good thing to make it more explicit. @VojtechVitek WDYT?