runSync method

  1. @override
List<ProcessResult> runSync(
  1. String script
)

Run one or multiple plain text command(s).

Commands can be split by line.

Commands can be on multiple line if ending with ^ or \.

Returns a list of executed command line results.

Compare to the async version, it is not possible to kill the spawn process nor to feed any input.

Implementation

@override
List<ProcessResult> runSync(
  String script,
) {
  var commands = scriptToCommands(script);

  var processResults = <ProcessResult>[];
  for (var command in commands) {
    // Display the comments
    if (isLineComment(command!)) {
      if (_options.commentVerbose) {
        stdout.writeln(command);
      }
      continue;
    }
    var parts = shellSplit(command);
    var executable = parts[0];
    var arguments = parts.sublist(1);

    // Find alias
    var alias = _options.environment.aliases[executable];
    if (alias != null) {
      // The alias itself should be split
      parts = shellSplit(alias);
      executable = parts[0];
      arguments = [...parts.sublist(1), ...arguments];
    }
    var processResult = runExecutableArgumentsSync(executable, arguments);
    processResults.add(processResult);
  }

  return processResults;
}