Index: runtime/bin/process.dart |
diff --git a/runtime/bin/process.dart b/runtime/bin/process.dart |
index 351465847f6efada58150c04bd14f73ae7b73d22..ac96ef98a4a405ba8a4292fbba0e8b74010ab6fc 100644 |
--- a/runtime/bin/process.dart |
+++ b/runtime/bin/process.dart |
@@ -3,47 +3,52 @@ |
// BSD-style license that can be found in the LICENSE file. |
/** |
- * [Process] objects are used to start new processes and interact with |
- * them. |
+ * [Process] is used to start new processes. |
*/ |
-interface Process default _Process { |
+class Process { |
/** |
- * Creates a new process object and starts a process running the |
- * [executable] with the specified [arguments]. When the process has |
- * been successfully started [onStart] is called. If the process |
- * fails to start [onError] is called. |
+ * Starts a process running the [executable] with the specified |
+ * [arguments]. Returns an [InteractiveProcess] object that can be |
+ * used to interact with the process. |
* |
* An optional [ProcessOptions] object can be passed to specify |
* options other than the executable and the arguments. |
- * |
- * No data can be written to the process stdin and the process |
- * cannot be closed nor killed before [onStart] has been invoked. |
*/ |
- Process.start(String executable, |
- List<String> arguments, |
- [ProcessOptions options]); |
+ static InteractiveProcess start(String executable, |
+ List<String> arguments, |
+ [ProcessOptions options]) { |
+ return _Process.start(executable, arguments, options); |
+ } |
/** |
- * Creates a new process object, starts a process and runs it |
- * non-interactively to completion. The process run is [executable] |
- * with the specified [arguments]. When the process has been |
- * successfully started [onStart] is called. If the process fails to |
- * start [onError] is called. |
+ * Starts a process and runs it non-interactively to completion. The |
+ * process run is [executable] with the specified [arguments]. |
* |
- * Options other than the executable and the arguments are specified |
- * using a [ProcessOptions] object. If no options are required, |
- * [null] can be passed as the options. |
+ * An optional [ProcessOptions] object can be passed to specify |
+ * options other than the executable and the arguments. |
* |
- * No communication via [stdin], [stdout] or [stderr] can take place |
- * with a non-interactive process. Instead, the process is run to |
- * completion at which point the exit code and stdout and stderr are |
- * supplied to the [callback] parameter. |
- */ |
- Process.run(String executable, |
- List<String> arguments, |
- ProcessOptions options, |
- void callback(int exitCode, String stdout, String stderr)); |
+ * Returns a [:Future<ProcessResult>:] that completes with the |
+ * result of running the process, i.e., exit code, standard out and |
+ * standard in. |
+ */ |
+ static Future<ProcessResult> run(String executable, |
+ List<String> arguments, |
+ [ProcessOptions options]) { |
+ return _Process.run(executable, arguments, options); |
+ } |
+} |
+/** |
+ * [InteractiveProcess] represents a process which users can |
+ * communicate with using streams. |
+ * |
+ * When the process has been successfully started [onStart] is |
+ * called. If the process fails to start [onError] is called. |
+ * |
+ * No data can be written to the process stdin and the process |
+ * cannot be closed nor killed before [onStart] has been invoked. |
+ */ |
+interface InteractiveProcess { |
Bob Nystrom
2012/05/10 17:14:21
The split between this and Process is unclear. Doe
Mads Ager (google)
2012/05/10 17:33:19
Thanks Bob! That makes a lot of sense to me. I hav
|
/** |
* Returns an input stream of the process stdout. |
* |
@@ -108,6 +113,28 @@ interface Process default _Process { |
/** |
+ * [ProcessResult] represents the result of running a non-interactive |
+ * process started with [:Process.run:]. |
+ */ |
+interface ProcessResult { |
+ /** |
+ * Exit code for the process. |
+ */ |
+ int get exitCode(); |
+ |
+ /** |
+ * Standard output from the process as a string. |
+ */ |
+ String get stdout(); |
+ |
+ /** |
+ * Standard error from the process as a string. |
+ */ |
+ String get stderr(); |
+} |
+ |
+ |
+/** |
* [ProcessOptions] represents the options that can be supplied when |
* starting a process. |
*/ |
@@ -156,7 +183,7 @@ class ProcessOptions { |
class ProcessException implements Exception { |
const ProcessException([String this.message, int this.errorCode = 0]); |
- String toString() => "ProcessException: $message"; |
+ String toString() => "ProcessException: $message ($errorCode)"; |
/** |
* Contains the system message for the process exception if any. |