run method
Future<ShellResult>
run(
- String executable,
- List<
String> arguments, { - String? workingDirectory,
- Map<
String, String> ? environment, - void onOutput(
- String line
override
Runs executable with arguments and waits for it to finish.
A non-zero exit code is returned in the result, not thrown.
Pass onOutput to receive each line of output as the command prints it,
from both standard output and standard error. The full output is still
returned in the result.
Implementation
@override
Future<ShellResult> run(
String executable,
List<String> arguments, {
String? workingDirectory,
Map<String, String>? environment,
void Function(String line)? onOutput,
}) async {
final call = ShellCall(
executable: executable,
arguments: arguments,
workingDirectory: workingDirectory,
environment: environment,
);
_calls.add(call);
if (_missing.contains(executable)) {
throw ProcessException(
executable,
arguments,
'No such file or directory',
2,
);
}
final result = _stubs[call.commandLine] ?? const ShellResult(exitCode: 0);
if (onOutput != null) {
// Like the real shell: every line of output, standard output first.
for (final text in [result.stdout, result.stderr]) {
const LineSplitter().convert(text).forEach(onOutput);
}
}
return result;
}