pipe static method

Future<ProcessResultData> pipe(
  1. List<List<String>> commands, {
  2. String? workingDirectory,
  3. Map<String, String>? environment,
  4. Duration? timeout = const Duration(seconds: 60),
})

Runs the commands one after another, each reading the output of the one before. It stops at the first failure and answers that result.

Implementation

static Future<ProcessResultData> pipe(
  List<List<String>> commands, {
  String? workingDirectory,
  Map<String, String>? environment,
  Duration? timeout = const Duration(seconds: 60),
}) async {
  if (commands.isEmpty) {
    throw ArgumentError.value(commands, 'commands', 'Empty pipe');
  }
  ProcessResultData? previous;
  for (final command in commands) {
    previous = await run(
      command,
      workingDirectory: workingDirectory,
      environment: environment,
      timeout: timeout,
      input: previous?.output,
    );
    if (previous.failed) {
      break;
    }
  }
  return previous!;
}