run method

  1. @override
Future<List<ProcessResult>> run(
  1. String script, {
  2. ShellOnProcessCallback? onProcess,
})

Run one or multiple plain text command(s).

Commands can be splitted by line.

Commands can be on multiple line if ending with ^ or \. (note that \ must be escaped too so you might have to enter \\).

Returns a list of executed command line results.

onProcess is called for each started process.

Implementation

@override
Future<List<ProcessResult>> run(
  String script, {
  ShellOnProcessCallback? onProcess,
}) async {
  var results = <ProcessResult>[];
  var commands = shellScriptSplitLines(script);

  for (var command in commands) {
    // Display the comments
    if (shellScriptLineIsComment(command)) {
      if (options.commentVerbose) {
        // ignore: avoid_print
        print(command);
      }
      continue;
    }
    var parts = shellSplit(command);
    var executable = parts[0];
    var arguments = parts.sublist(1);
    results.add(
      await runExecutableArguments(
        executable,
        arguments,
        onProcess: onProcess,
      ),
    );
  }
  return results;
}