Stdin, Stdout, and Process Args
Build interactive CLI programs.
Stdin, Stdout, and Process Args is a free Dart Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Three Standard Streams
Command-line programs talk through three channels: stdin for input, stdout for normal output, and stderr for errors.
stdout vs print
print adds a newline and goes to stdout. For finer control, write directly with stdout.write and no extra newline appears.
stdout.write('Loading');Errors Go to stderr
Send warnings to stderr, not stdout. That keeps real output clean when users pipe your program elsewhere.
stderr.writeln('Could not find file');Read a Line of Input
Ask the user a question, then grab their answer with stdin.readLineSync. It pauses until they press Enter.
final name = stdin.readLineSync();Input Can Be Null
readLineSync returns a nullable String. If the stream closes with no input, you get null, so handle that case.
final answer = stdin.readLineSync() ?? '';A Tiny Prompt Loop
Combine a write and a read to build a prompt. Print a question, read the reply, then act on it, all in a few lines.
stdout.write('Name? '); final n = stdin.readLineSync();Command-Line Arguments
Your main can accept a List of String args. Whatever the user types after the program name lands there in order.
void main(List<String> args) { print(args); }Read One Argument
Access args by index like any list. Always check args.isEmpty first so a missing argument does not crash you.
if (args.isNotEmpty) print(args[0]);Parse Flags With args
For real CLIs, the args package turns flags and options into a tidy parsed result instead of manual index juggling.
import 'package:args/args.dart';Set an Exit Code
Tell the shell how things went with exit. Zero means success, anything else signals an error to scripts that call you.
exit(1);Echo Mode Off
For passwords, hide typed characters by setting stdin.echoMode to false before reading the line.
stdin.echoMode = false;Quick Check
Where should a CLI tool send error messages so piped output stays clean?
Recap
You can now write to stdout and stderr, read input with stdin, accept command-line args, and set an exit code. Your CLI is interactive.
Frequently asked questions
Is the “Stdin, Stdout, and Process Args” lesson free?
Yes — the full text of “Stdin, Stdout, and Process Args” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.
What will I learn in “Stdin, Stdout, and Process Args”?
Build interactive CLI programs. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Dart Academy?
No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Stdin, Stdout, and Process Args” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Dart Academy lesson?
Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Reading and Writing Files
- Directories, Paths, and FileSystemEntity
- Streaming Large Files
- Stdin, Stdout, and Process Args