CodeBlanks Logo Icon CodeBlanks

dart run

Learn to run programs with dart run.

The dart run command

To run a Dart program, type dart run file.dart in the terminal. This command compiles the file and runs it immediately.

If the Dart SDK is installed, the dart command is on the PATH. If not, install the Flutter SDK first (Dart comes with it).

If an error occurs during execution, Dart shows it with a line number. If there is no error, the terminal returns to the command line when the program finishes.

Output and stdout

When the program runs, everything you write with print goes to the standard output stream (stdout). The terminal shows this stream on the screen.

If the program prints an error message, it usually goes to the standard error stream (stderr); most terminals show it in red.

Later we will see stdout.write and stderr.write too; they write without adding a newline.

Practice Ready to run message

Write a program that prints Terminal ready when run. Do not forget the void main() skeleton.

Starter code

main.dart
// Complete your program

Sample solution

main.dart
void main() {
  print("Terminal ready");
}

Expected output

Terminal ready

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Command to run merhaba.dart?

main.dart
dart run merhaba.dart
  • dart start merhaba.dart
  • dart run merhaba.dart Correct answer
  • run dart merhaba
  • dart execute merhaba

Explanation: The dart run command compiles and runs the file.

2 Run subcommand

Question
dart ____ merhaba.dart
Answer
dart run merhaba.dart

Explanation: The form dart run file.dart is used.

3 Terminal concepts

Term Meaning
dart run Runs the file
.dart Dart file extension
stdout Output stream
print Writes to screen

All lessons in Beginner