runDartVM method

Future<ProcessInfo> runDartVM(
  1. String entrypoint,
  2. List<String> args, {
  3. bool enableVMService = false,
  4. String? vmServiceAddress,
  5. int? vmServicePort,
  6. bool pauseIsolatesOnStart = false,
  7. bool pauseIsolatesOnExit = false,
  8. bool pauseIsolatesOnUnhandledExceptions = false,
  9. String? workingDirectory,
  10. bool handleSignals = false,
  11. bool redirectOutput = false,
  12. bool catchOutput = false,
  13. String stdoutFilter(
    1. String o
    )?,
  14. String stderrFilter(
    1. String o
    )?,
  15. void onSignal(
    1. ProcessSignal signal
    )?,
})

Runs a new Dart VM.

  • entrypoint is the Dart entrypoint, usually a Dart file.
  • args is the arguments to pass to the entrypoint.
  • workingDirectory is the Process working directory. If null will use the current working directory.
  • enableVMService - if true runs Dart VM with --enable-vm-service.
    • vmServiceAddress - the VM Service listen address.
    • vmServicePort - the VM Service listen port.
    • pauseIsolatesOnStart - if true pauses Isolate on VM start.
    • pauseIsolatesOnExit - if true pauses Isolate on VM exit.
    • pauseIsolatesOnUnhandledExceptions - if true pauses Isolate on Unhandled Exception.
  • If handleSignals is true kills the Process if SIGINT or SIGTERM is triggered in the host/current process.
  • If redirectOutput is true redirects the Process outputs to the host/current stdout and stderr.
  • If catchOutput is true catches the Process outputs to ProcessInfo.outputBuffer and ProcessInfo.errorOutputBuffer.
  • stdoutFilter is a filter for the Process stdout. Useful to remove sensitive data.
  • stderrFilter is a filter for the Process stderr. Useful to remove sensitive data.

Implementation

Future<ProcessInfo> runDartVM(
  String entrypoint,
  List<String> args, {
  bool enableVMService = false,
  String? vmServiceAddress,
  int? vmServicePort,
  bool pauseIsolatesOnStart = false,
  bool pauseIsolatesOnExit = false,
  bool pauseIsolatesOnUnhandledExceptions = false,
  String? workingDirectory,
  bool handleSignals = false,
  bool redirectOutput = false,
  bool catchOutput = false,
  String Function(String o)? stdoutFilter,
  String Function(String o)? stderrFilter,
  void Function(ProcessSignal signal)? onSignal,
}) async {
  String vmService = '';
  if (!enableVMService) {
    pauseIsolatesOnStart = false;
    pauseIsolatesOnExit = false;
    pauseIsolatesOnUnhandledExceptions = false;
  } else {
    if (vmServicePort != null && vmServicePort <= 1) {
      vmServicePort = null;
    }

    if (vmServiceAddress != null) {
      vmServiceAddress = vmServiceAddress.trim();
      if (vmServiceAddress.isEmpty) {
        vmServiceAddress = null;
      }
    }

    if (vmServicePort == null) {
      var freePort = await getFreeListenPort(
          ports: [8181, 8171, 8191], startPort: 8161, endPort: 8191);

      if (freePort != 8181) {
        vmServicePort = freePort;
      }
    }

    if (vmServiceAddress != null) {
      vmServicePort ??= 8181;
      vmService = '=$vmServicePort/$vmServiceAddress';
    } else if (vmServicePort != null) {
      vmService = '=$vmServicePort';
    }
  }

  return runProcess(
    'dart',
    [
      if (enableVMService) '--enable-vm-service$vmService',
      if (pauseIsolatesOnStart) '--pause-isolates-on-start',
      if (pauseIsolatesOnExit) '--pause-isolates-on-exit',
      if (pauseIsolatesOnUnhandledExceptions)
        '--pause-isolates-on-unhandled-exceptions',
      'run',
      entrypoint,
      ...args
    ],
    workingDirectory: workingDirectory,
    handleSignals: handleSignals,
    redirectOutput: redirectOutput,
    catchOutput: catchOutput,
    stdoutFilter: stdoutFilter,
    stderrFilter: stderrFilter,
    onSignal: onSignal,
  );
}