Index: sdk/lib/io/process.dart |
diff --git a/sdk/lib/io/process.dart b/sdk/lib/io/process.dart |
index 0cf7126ac4b229b46ad36828459b15df4f689146..828145e8304bce61369dd94fedfcd0ba7b80ab04 100644 |
--- a/sdk/lib/io/process.dart |
+++ b/sdk/lib/io/process.dart |
@@ -85,8 +85,97 @@ void sleep(Duration duration) { |
int get pid => _ProcessUtils._pid(null); |
/** |
- * [Process] is used to start new processes using the static |
- * [start] and [run] methods. |
+ * The means to execute a program. |
+ * |
+ * Use the static [start] and [run] methods to start a new process. |
+ * The run method executes the process non-interactively to completion. |
+ * In contrast, the start method allows your code to interact with the |
+ * running process. |
+ * |
+ * ## Start a process with the run method |
+ * |
+ * The following code sample uses the run method to create a process |
+ * that runs the UNIX command `ls`, which lists the contents of a directory. |
+ * The run method completes with a [ProcessResult] object when the process |
+ * terminates. This provides access to the output and exit code from the |
+ * process. The run method does not return a Process object; this prevents your |
+ * code from interacting with the running process. |
+ * |
+ * import 'dart:io'; |
+ * |
+ * main() { |
+ * // List all files in the current directory in UNIX-like systems. |
+ * Process.run('ls', ['-l']).then((ProcessResult results) { |
+ * print(results.stdout); |
+ * }); |
+ * } |
+ * |
+ * ## Start a process with the start method |
+ * |
+ * The following example uses start to create the process. |
+ * The start method returns a [Future] for a Process object. |
+ * When the future completes the process is started and |
+ * your code can interact with the |
+ * Process: writing to stdin, listening to stdout, and so on. |
+ * |
+ * The following sample starts the UNIX `cat` utility, which when given no |
+ * command-line arguments, echos its input. |
+ * The program writes to the process's standard input stream |
+ * and prints data from its standard output stream. |
+ * |
+ * import 'dart:io'; |
+ * import 'dart:convert'; |
+ * |
+ * main() { |
+ * Process.start('cat', []).then((Process process) { |
+ * process.stdout |
+ * .transform(UTF8.decoder) |
+ * .listen((data) { print(data); }); |
+ * process.stdin.writeln('Hello, world!'); |
+ * process.stdin.writeln('Hello, galaxy!'); |
+ * process.stdin.writeln('Hello, universe!'); |
+ * }); |
+ * } |
+ * |
+ * ## Standard I/O streams |
+ * |
+ * As seen in the previous code sample, you can interact with the Process's |
+ * standard output stream through the getter [stdout], |
+ * and you can interact with the Process's standard input stream through |
+ * the getter [stdin]. |
+ * In addition, Process provides a getter [stderr] for using the Process's |
+ * standard error stream. |
+ * |
+ * A Process's streams are distinct from the top-level streams |
+ * for the current program. |
+ * |
+ * ## Exit codes |
+ * |
+ * Call the [exitCode] method to get the exit code of the process. |
+ * The exit code indicates whether the program terminated successfully |
+ * (usually indicated with an exit code of 0) or with an error. |
+ * |
+ * If the start method is used, the exitCode is available through a future |
+ * on the Process object (as shown in the example below). |
+ * If the run method is used, the exitCode is available |
+ * through a getter on the ProcessResult instance. |
+ * |
+ * import 'dart:io'; |
+ * |
+ * main() { |
+ * Process.start('ls', ['-l']).then((process) { |
+ * // Get the exit code from the new process. |
+ * process.exitCode.then((exitCode) { |
+ * print('exit code: $exitCode'); |
+ * }); |
+ * }); |
+ * } |
+ * |
+ * ## Other resources |
+ * |
+ * [Dart by Example](https://www.dartlang.org/dart-by-example/#dart-io-and-command-line-apps) |
+ * provides additional task-oriented code samples that show how to use |
+ * various API from the [dart:io] library. |
*/ |
abstract class Process { |
/** |