execRead function
Executes the given process, returning its output streams line-by-line.
This method is similar to exec, but simplifying the process of reading the process output into Lists.
The returned object contains the process stdout and stderr outputs as
Lists<String>
where each item is a line of output.
Output lines may be filtered out by providing stdoutFilter
or stderrFilter
(the filter must return true
to keep a line, or false
to exclude it).
This method throws ProcessExitCodeException in case the process' exit code
is not considered successful by isCodeSuccessful
,
or ProcessException in case the process could not be executed at all.
Implementation
Future<ExecReadResult> execRead(Future<Process> process,
{String name = '',
bool Function(String) stdoutFilter = filterNothing,
bool Function(String) stderrFilter = filterNothing,
bool Function(int) isCodeSuccessful = _onlyZero}) async {
final stdout = StdStreamConsumer(keepLines: true, filter: stdoutFilter);
final stderr = StdStreamConsumer(keepLines: true, filter: stderrFilter);
final code = await _exec(await process, name, stdout, stderr);
final result = ExecReadResult(code, stdout.lines, stderr.lines);
if (isCodeSuccessful(code)) {
return result;
}
throw ProcessExitCodeException(code, name, stdout.lines, stderr.lines);
}