Contents

dart run

The dart run command supports running a Dart program—located in a file, in the current package, or in one of the dependencies of the current package—from the command line. This command provides functionality that was previously in pub run and the Dart VM tool. To run a program from an arbitrary location, use the pub global command.

dart run [options] [<DART_FILE> | <PACKAGE_TARGET>] [args]

Here’s an example of creating a new app and running it:

$ dart create myapp
$ cd myapp
$ dart run

Running a Dart file

You can run a Dart file by passing its relative path:

$ dart run tool/debug.dart

Running a program that’s in a package

The instructions in this section assume that you’re executing the dart run command from the directory that’s at the top of a Dart package (the current package). For information on the directory structure of Dart packages, see package layout conventions.

In a depended-on package

You can run programs that are distributed in the bin directory of any package that the current package depends on. To run such a program, specify the depended-on package name and the program name. You can omit the program name if it’s the same as the package name.

For example, say you’re in the top directory of a package that depends on the bar package. To run the main program that’s in the bar package (bin/bar.dart), you can use this command:

$ dart run bar

If the program name doesn’t match the package name, use the form <package name>:<program name>. For example, to run the program bin/baz.dart that’s in the bar package, use this command:

$ dart run bar:baz

The bin directory is the only place with visible programs. All other directories in the depended-on package are private.

In the current package

When the current directory matches the package name (that is, you’re in the directory that matches the name property in the pubspec), then you can omit the package name. If the program name matches the package name (that is, it’s the main program), then you can also omit the program name.

Here’s the shortest form of dart run, which runs the main program for the current package. For example, if you’re in the top directory of the foo package, this command runs bin/foo.dart:

$ dart run

If the program name doesn’t match the package name, then add a colon and the program name. For example, this command runs bin/baz.dart in the current package:

$ dart run :baz

To run a program that’s in the current package but not in the bin directory, pass a relative path (as shown before):

$ dart run tool/debug.dart

Supplying arguments to main()

To supply arguments to the main() function, put them at the end of the command:

$ dart run tool/debug.dart arg1 arg2

When you’re running the main program for the current package, add the package name. Here’s an example of running bin/foo.dart with arguments while you’re in the top directory of the foo package:

$ dart run foo arg1 arg2

Debugging

To enable debugging, add one or more of these common debugging options to your dart run command:

To learn more about other debugging options, run dart run --help.

Enabling experimental features

To enable new features and enhancements that are currently in development, use experiment flags.