dart (Dart VM)
You can use the dart tool (bin/dart
) to run Dart command-line apps such asserver-side scripts, programs, and servers.
Basic usage
Here’s an example of running a Dart file on the command line:
$ dart --enable-asserts test.dart
Note: You can’t use dart
to run mobile apps or web apps(apps that include dart:html
, or that depend on librariesthat use the browser environment).
Options
Common command-line options for dart include:
—enable-asserts
- Enables
assert
statements. When asserts are enabled, anassert statementchecks a boolean condition, raising an exception if the condition is false. —packages=<path>
- Specifies the path to the package resolution configuration file.For more information, seePackage Resolution Configuration File.This option cannot be used with
—package-root
. -p <path>
or-package-root=<path>
- Specifies where to find imported libraries.This option cannot be used with
—packages
. —old_gen_heap_size=<num>
- Sets the upper limit ofold space to
<num>
MB. —version
- Displays VM version information.
-h
or—help
- Displays help. (Add
-v
for information about all options.)
Observatory options
Observatory is a tool for profiling and debugging your apps.You can use the following flags to enable Observatory and toinstruct the VM to delay the start up, or the exit, of an isolate:
—enable-vm-service
- Enables Observatory on localhost port 8181.
—enable-vm-service=<port>
- Enables Observatory on localhost for the specific port.
—enable-vm-service=<port>/<IP address>
- Enables Observatory on an external network using the specifiedIP address and port. For example:
—enable-vm-service=9999/0.0.0.0
—pause-isolates-on-exit
- Causes the VM to pause each isolate that would otherwise exit.If your standalone app executes quickly,it might exit before you can open Observatory. To avoid this situation,specify this flag on startup. You must explicitly release all isolatesin the Observatory debugger.
—pause-isolates-on-start
- Causes the VM to pause before starting any isolate.You must explicitly start each isolate in theObservatory debugger.
—observe
- A shortcut that combines
—enable-vm-service
and—pause-isolates-on-exit
. —profile
- On Windows, Observatory’sCPU Profiler screenis disabled by default. Use this option to enable it.
The following is an example Observatory run:
$ dart --observe <script>.dart
For more information, see Observatory.
Snapshot option
You can also generate snapshots:
—snapshot=<filename>
- Generates a snapshot in the specified file. For informationon generating and running snapshots, seeSnapshots on GitHub.