runDartVM method
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 stdoutFilter(
- String o
- String stderrFilter(
- String o
- void onSignal(
- ProcessSignal signal
Runs a new Dart VM.
entrypoint
is the Dart entrypoint, usually a Dart file.args
is the arguments to pass to theentrypoint
.workingDirectory
is the Process working directory. Ifnull
will use the current working directory.enableVMService
- iftrue
runs Dart VM with--enable-vm-service
.- If
handleSignals
istrue
kills the Process ifSIGINT
orSIGTERM
is triggered in the host/current process. - If
redirectOutput
istrue
redirects the Process outputs to the host/current stdout and stderr. - If
catchOutput
istrue
catches the Process outputs to ProcessInfo.outputBuffer and ProcessInfo.errorOutputBuffer. stdoutFilter
is a filter for the Processstdout
. Useful to remove sensitive data.stderrFilter
is a filter for the Processstderr
. 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,
);
}