exec function

Future<int> exec(
  1. Future<Process> process, {
  2. String name = '',
  3. dynamic onStdoutLine(
    1. String
    )?,
  4. dynamic onStderrLine(
    1. String
    )?,
})

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);
  onStderrLine ??= StdStreamConsumer(printToStderr: true);

  return _exec(proc, name, onStdoutLine, onStderrLine);
}