runScript method

  1. @override
Future<ShellProcessResults> runScript(
  1. String script, {
  2. ShellCommandRunOptions? options,
})

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.

onProcess is called for each started process.

Implementation

@override
Future<ShellProcessResults> runScript(
  String script, {
  ShellCommandRunOptions? options,
}) {
  // devPrint('Running $script');
  return _runLocked((runId) async {
    var commands = shellScriptSplitLines(script);

    var processResults = <ShellProcessResult>[];
    for (var command in commands) {
      // Check if killed
      _checkKilled(runId);

      // Display the comments
      if (_handleLineComment(command)) {
        continue;
      }
      var shellCommand = ShellCommand.parse(command);

      var processResult = await _lockedRunCommand(
        runId,
        shellCommand,
        options: options,
      );
      processResults.add(processResult);
    }

    var result = ShellProcessResultInternalList.fromList(
      this,
      processResults,
    );
    return result;
  });
}