run method
Execute command
on the remote side non-interactively. Returns a
Future<String?> that completes with the output of the command.
This is a convenience method over execute. If stdout
is false,
the standard output of the command will be ignored. If stderr
is
false, the standard error of the command will be ignored.
Implementation
Future<Uint8List> run(
String command, {
bool runInPty = false,
bool stdout = true,
bool stderr = true,
Map<String, String>? environment,
}) async {
final session = await execute(
command,
pty: runInPty ? const SSHPtyConfig() : null,
environment: environment,
);
final result = BytesBuilder(copy: false);
final stdoutDone = Completer<void>();
final stderrDone = Completer<void>();
session.stdout.listen(
stdout ? result.add : (_) {},
onDone: stdoutDone.complete,
onError: stderrDone.completeError,
);
session.stderr.listen(
stderr ? result.add : (_) {},
onDone: stderrDone.complete,
onError: stderrDone.completeError,
);
await stdoutDone.future;
await stderrDone.future;
return result.takeBytes();
}