exec function
Executes the given process, returning its exit code.
onStdoutLine
and onStderrLine
can be provided in order to consume
the process' stdout and stderr streams, respectively (the process's output
is interpreted as utf8 emitted line by line).
If not provided, the streams are consumed and printed to stdout or stderr, respectively.
Instances of StdStreamConsumer
can be used as onStdoutLine
and
onStderrLine
functions in order to easily configure what to do with the
process' output.
Implementation
Future<int> exec(Future<Process> process,
{String name = '',
Function(String)? onStdoutLine,
Function(String)? onStderrLine}) async {
final proc = await process;
onStdoutLine ??= StdStreamConsumer(printToStdout: true).call;
onStderrLine ??= StdStreamConsumer(printToStderr: true).call;
return _exec(proc, name, onStdoutLine, onStderrLine);
}