runAsString method
Implementation
Future<String> runAsString(
String executable,
List<String> arguments, {
String? errorMessage,
}) async {
// late final cmd = '$executable ${arguments.join(' ')}';
final started = Process.start(
executable,
arguments,
workingDirectory: this == Directory.current ? null : path,
mode: ProcessStartMode.normal,
);
final process = await started;
final result = process.stdout.transform(utf8.decoder).join();
final stderrStream = process.stderr.listen(
(event) {
stderr.add(event);
},
);
Future.wait([
result,
stderrStream.asFuture(),
]);
// !!! exit code can be non-zero with still a valid output
// await started.join(
// errorMessage: errorMessage ??
// "Error running command: $executable ${arguments.join(' ')}",
// );
await process.exitCode;
return await result;
}