Dart ProcessStartMode
last modified October 18, 2026
The ProcessStartMode class in Dart controls how a new process
should be started. It is used with the Process.start method.
ProcessStartMode determines how the standard input, output, and error streams
are handled. It's part of Dart's dart:io library for system-level
operations.
Basic Definition
ProcessStartMode is a final class with static constants that
define process execution modes. It specifies how the process streams should be
connected to the parent process.
The available modes are: normal, inheritStdio,
detached, and detachedWithStdio. Each serves
different use cases for process execution.
Normal Mode
This example shows the default normal mode where pipes are created
for all standard streams.
import 'dart:convert';
import 'dart:io';
void main() async {
var process = await Process.start(
'dart',
['--version'],
mode: ProcessStartMode.normal
);
var output = await process.stdout.transform(utf8.decoder).join();
print('Dart version: $output');
}
In normal mode, the process creates pipes for stdin, stdout, and stderr. The parent process can read/write these streams. This is the default mode.
$ dart main.dart Dart version: Dart SDK version: 3.13.5 (stable)
Detached Mode
This example demonstrates detached mode where the process runs
independently without stream connections.
import 'dart:io';
void main() async {
var process = await Process.start(
'sleep',
['5'],
mode: ProcessStartMode.detached
);
print('Process started with PID: ${process.pid}');
print('Process will run independently for 5 seconds');
}
In detached mode, the process runs independently with no stream connections. The parent process cannot communicate with the child process via streams.
$ dart main.dart Process started with PID: 12345 Process will run independently for 5 seconds
Detached With Stdio
This example shows detachedWithStdio mode where the process runs
independently but keeps its standard streams connected to the creator.
import 'dart:convert';
import 'dart:io';
void main() async {
var process = await Process.start(
'dart',
['--version'],
mode: ProcessStartMode.detachedWithStdio
);
print('Process started with PID: ${process.pid}');
var output = await process.stdout.transform(utf8.decoder).join();
print('Output: ${output.trim()}');
}
In this mode, the process runs detached but its stdin, stdout, and stderr stay connected to the creator through pipes. The creator can read and write those streams, and the child keeps running even if the creator exits.
$ dart main.dart Process started with PID: 12346 Output: Dart SDK version: 3.13.5 (stable)
Inherit Stdio
This example demonstrates inheritStdio mode where the process
shares the parent's standard streams.
import 'dart:io';
void main() async {
var process = await Process.start(
'echo',
['Hello from child process'],
mode: ProcessStartMode.inheritStdio
);
await process.exitCode;
print('Child process completed');
}
In inheritStdio mode, the child process shares the parent's stdin,
stdout, and stderr. The output appears directly in the console without
redirection.
$ dart main.dart Hello from child process Child process completed
Combining inheritStdio with a Shell
This example runs a command through the system shell while letting the child
use the parent's standard streams. Both runInShell and
mode are parameters of Process.start, not
Process.run.
import 'dart:io';
void main() async {
var process = await Process.start(
'ls',
['-l'],
runInShell: true,
mode: ProcessStartMode.inheritStdio
);
var code = await process.exitCode;
print('Exit code: $code');
}
With inheritStdio, the listing is written directly to the parent's
stdout instead of being returned in a ProcessResult.
$ dart main.dart total 8 -rw-r--r-- 1 user group 123 Apr 4 10:00 main.dart Exit code: 0
Best Practices
- Default: Use normal mode when you need stream communication
- Background: Use detached for long-running background tasks
- Console: Use inheritStdio for simple command-line tools
- Security: Be careful with inheritStdio for sensitive input
Source
Dart ProcessStartMode Documentation
This tutorial covered Dart's ProcessStartMode class with practical examples showing different process execution modes and their use cases.
Author
List all Dart tutorials.