Issue #3584. If pipe is synchronous, such as stdio, then write data sync...

...hronously.

Add tests to check piped stdout does not lose data on exit.