Implement fflush for stdout and stderr. #2770.
Add test for fflush behavior.
Merge pull request #2771 from juj/implement_fflush

implement_fflush