DO NOT MERGE: Refactored functions that copy sdout and stderr to strings to use a callback.

BUG: 28609499

Change-Id: I04aea346e18678ea00797f7f659480edba4436c2
(cherry picked from commit 07ac8554b477dc81579a5e63a2fbabc740fa8a92)
(cherry picked from commit d18854218ec1e9fa2659f6c8be1ca17adefe68fb)
5 files changed