runToFile method
Runs executable to the end, writing what it prints to stdout into
file byte for byte, as adb exec-out needs. Returns its exit code and
what it printed to stderr.
Implementation
Future<ProcessResult> runToFile(
String executable,
List<String> arguments,
String file,
) async {
final Process process = await Process.start(executable, arguments);
await process.stdin.close();
final IOSink sink = File(file).openWrite();
final List<Object?> finished = await Future.wait([
process.stdout.pipe(sink),
process.stderr.transform(const Utf8Decoder(allowMalformed: true)).join(),
process.exitCode,
]);
return ProcessResult(process.pid, finished[2] as int, '', finished[1]);
}