run method
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<List<ProcessResult>> run(String script,
{void Function(Process process)? onProcess}) {
// devPrint('Running $script');
return _runLocked((runId) async {
var commands = scriptToCommands(script);
var processResults = <ProcessResult>[];
for (var command in commands) {
if (_killedRunId >= runId) {
throw ShellException('Script was killed', null);
}
// 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 = await _lockedRunExecutableArguments(
runId, executable, arguments,
onProcess: onProcess);
processResults.add(processResult);
}
return processResults;
});
}