call method

Future<ProcessDetails> call(
  1. String executable,
  2. List<String> arguments, {
  3. String? workingDirectory,
  4. Map<String, String>? environment,
  5. bool includeParentEnvironment = true,
  6. bool runInShell = false,
  7. ProcessStartMode mode = io.ProcessStartMode.normal,
})

Implementation

Future<ProcessDetails> call(
  String executable,
  List<String> arguments, {
  String? workingDirectory,
  Map<String, String>? environment,
  bool includeParentEnvironment = true,
  bool runInShell = false,
  io.ProcessStartMode mode = io.ProcessStartMode.normal,
}) async {
  final process = await io.Process.start(
    executable,
    arguments,
    workingDirectory: workingDirectory,
    environment: environment,
    includeParentEnvironment: includeParentEnvironment,
    runInShell: runInShell,
    mode: mode,
  );

  final stdoutController = StreamController<List<int>>.broadcast();
  final stderrController = StreamController<List<int>>.broadcast();

  try {
    process.stdout.listen(stdoutController.add);
  } catch (_) {}

  try {
    process.stderr.listen(stderrController.add);
  } catch (_) {}

  Stream<String> stdout() async* {
    try {
      yield* stdoutController.stream.transform(utf8.decoder);
    } catch (_) {
      // ignore
    }
  }

  Stream<String> stderr() async* {
    try {
      yield* stderrController.stream.transform(utf8.decoder);
    } catch (_) {
      // ignore
    }
  }

  return ProcessDetails(
    stdout: stdout().join(),
    stderr: stderr().join(),
    exitCode: process.exitCode,
  );
}