dart run
- Dart course
- Beginner
- Lesson 3/116
- 4 min
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
// Complete your programSample solution
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?
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
dart ____ merhaba.dart
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 |