tryProcessRunSync function

ProcessResult? tryProcessRunSync(
  1. String executable,
  2. List<String> args, {
  3. String? workingDirectory,
  4. Map<String, String>? environment,
  5. bool includeParentEnvironment = true,
  6. bool runInShell = false,
  7. Encoding? stdoutEncoding = systemEncoding,
  8. Encoding? stderrEncoding = systemEncoding,
  9. void onProcessException(
    1. ProcessException exception,
    2. StackTrace stackTrace
    )?,
})

Tries to synchronously run the executable with the provided args.

Returns null if Process.runSync throws a ProcessException.

Implementation

ProcessResult? tryProcessRunSync(
  String executable,
  List<String> args, {
  String? workingDirectory,
  Map<String, String>? environment,
  bool includeParentEnvironment = true,
  bool runInShell = false,
  Encoding? stdoutEncoding = systemEncoding,
  Encoding? stderrEncoding = systemEncoding,
  void Function(
    ProcessException exception,
    StackTrace stackTrace,
  )? onProcessException,
}) {
  try {
    return Process.runSync(
      executable,
      args,
      workingDirectory: workingDirectory,
      environment: environment,
      includeParentEnvironment: includeParentEnvironment,
      runInShell: runInShell,
      stdoutEncoding: stdoutEncoding,
      stderrEncoding: stderrEncoding,
    );
  } on ProcessException catch (exp, st) {
    onProcessException?.call(exp, st);
    return null;
  }
}