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 cc6ebb58e9980a7ac271450c7f34102a6eba7c62)
(cherry picked from commit ed602edefebb3477a727a77b341e3d7107152179)
5 files changed