OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 // TODO(ager): The only reason for this class is that we | 7 // TODO(ager): The only reason for this class is that we |
8 // cannot patch a top-level at this point. | 8 // cannot patch a top-level at this point. |
9 class _ProcessUtils { | 9 class _ProcessUtils { |
10 external static void _exit(int status); | 10 external static void _exit(int status); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 * that the change of directory occurs before executing the process on some | 76 * that the change of directory occurs before executing the process on some |
77 * platforms, which may have impact when using relative paths for the | 77 * platforms, which may have impact when using relative paths for the |
78 * executable and the arguments. | 78 * executable and the arguments. |
79 * | 79 * |
80 * Use [environment] to set the environment variables for the process. If not | 80 * Use [environment] to set the environment variables for the process. If not |
81 * set the environment of the parent process is inherited. Currently, only | 81 * set the environment of the parent process is inherited. Currently, only |
82 * US-ASCII environment variables are supported and errors are likely to occur | 82 * US-ASCII environment variables are supported and errors are likely to occur |
83 * if an environment variable with code-points outside the US-ASCII range is | 83 * if an environment variable with code-points outside the US-ASCII range is |
84 * passed in. | 84 * passed in. |
85 * | 85 * |
| 86 * If [includeParentEnvironment] is `true`, the process's environment will |
| 87 * include the parent process's environment, with [environment] taking |
| 88 * precedence. Default is `true`. |
| 89 * |
86 * If [runInShell] is true, the process will be spawned through a system | 90 * If [runInShell] is true, the process will be spawned through a system |
87 * shell. On Linux and Mac OS, [:/bin/sh:] is used, while | 91 * shell. On Linux and Mac OS, [:/bin/sh:] is used, while |
88 * [:%WINDIR%\system32\cmd.exe:] is used on Windows. | 92 * [:%WINDIR%\system32\cmd.exe:] is used on Windows. |
89 * | 93 * |
90 * Users must read all data coming on the [stdout] and [stderr] | 94 * Users must read all data coming on the [stdout] and [stderr] |
91 * streams of processes started with [:Process.start:]. If the user | 95 * streams of processes started with [:Process.start:]. If the user |
92 * does not read all data on the streams the underlying system | 96 * does not read all data on the streams the underlying system |
93 * resources will not be freed since there is still pending data. | 97 * resources will not be freed since there is still pending data. |
94 */ | 98 */ |
95 external static Future<Process> start( | 99 external static Future<Process> start( |
96 String executable, | 100 String executable, |
97 List<String> arguments, | 101 List<String> arguments, |
98 {String workingDirectory, | 102 {String workingDirectory, |
99 Map<String, String> environment, | 103 Map<String, String> environment, |
| 104 bool includeParentEnvironment: true, |
100 bool runInShell: false}); | 105 bool runInShell: false}); |
101 | 106 |
102 /** | 107 /** |
103 * Starts a process and runs it non-interactively to completion. The | 108 * Starts a process and runs it non-interactively to completion. The |
104 * process run is [executable] with the specified [arguments]. | 109 * process run is [executable] with the specified [arguments]. |
105 * | 110 * |
106 * Use [workingDirectory] to set the working directory for the process. Note | 111 * Use [workingDirectory] to set the working directory for the process. Note |
107 * that the change of directory occurs before executing the process on some | 112 * that the change of directory occurs before executing the process on some |
108 * platforms, which may have impact when using relative paths for the | 113 * platforms, which may have impact when using relative paths for the |
109 * executable and the arguments. | 114 * executable and the arguments. |
110 * | 115 * |
111 * Use [environment] to set the environment variables for the process. If not | 116 * Use [environment] to set the environment variables for the process. If not |
112 * set the environment of the parent process is inherited. Currently, only | 117 * set the environment of the parent process is inherited. Currently, only |
113 * US-ASCII environment variables are supported and errors are likely to occur | 118 * US-ASCII environment variables are supported and errors are likely to occur |
114 * if an environment variable with code-points outside the US-ASCII range is | 119 * if an environment variable with code-points outside the US-ASCII range is |
115 * passed in. | 120 * passed in. |
116 * | 121 * |
| 122 * If [includeParentEnvironment] is `true`, the process's environment will |
| 123 * include the parent process's environment, with [environment] taking |
| 124 * precedence. Default is `true`. |
| 125 * |
117 * If [runInShell] is true, the process will be spawned through a system | 126 * If [runInShell] is true, the process will be spawned through a system |
118 * shell. On Linux and Mac OS, `/bin/sh` is used, while | 127 * shell. On Linux and Mac OS, `/bin/sh` is used, while |
119 * `%WINDIR%\system32\cmd.exe` is used on Windows. | 128 * `%WINDIR%\system32\cmd.exe` is used on Windows. |
120 * | 129 * |
121 * The encoding used for decoding `stdout` and `stderr` into text is | 130 * The encoding used for decoding `stdout` and `stderr` into text is |
122 * controlled through [stdoutEncoding] and [stderrEncoding]. The | 131 * controlled through [stdoutEncoding] and [stderrEncoding]. The |
123 * default encoding is `Encoding.SYSTEM`. If `null` is used no | 132 * default encoding is `Encoding.SYSTEM`. If `null` is used no |
124 * decoding will happen and the [ProcessResult] will hold binary | 133 * decoding will happen and the [ProcessResult] will hold binary |
125 * data. | 134 * data. |
126 * | 135 * |
127 * Returns a `Future<ProcessResult>` that completes with the | 136 * Returns a `Future<ProcessResult>` that completes with the |
128 * result of running the process, i.e., exit code, standard out and | 137 * result of running the process, i.e., exit code, standard out and |
129 * standard in. | 138 * standard in. |
130 */ | 139 */ |
131 external static Future<ProcessResult> run( | 140 external static Future<ProcessResult> run( |
132 String executable, | 141 String executable, |
133 List<String> arguments, | 142 List<String> arguments, |
134 {String workingDirectory, | 143 {String workingDirectory, |
135 Map<String, String> environment, | 144 Map<String, String> environment, |
| 145 bool includeParentEnvironment: true, |
136 bool runInShell: false, | 146 bool runInShell: false, |
137 Encoding stdoutEncoding: Encoding.SYSTEM, | 147 Encoding stdoutEncoding: Encoding.SYSTEM, |
138 Encoding stderrEncoding: Encoding.SYSTEM}); | 148 Encoding stderrEncoding: Encoding.SYSTEM}); |
139 | 149 |
140 /** | 150 /** |
141 * Returns the standard output stream of the process as a [:Stream:]. | 151 * Returns the standard output stream of the process as a [:Stream:]. |
142 * | 152 * |
143 * Throws an [UnsupportedError] if the process is | 153 * Throws an [UnsupportedError] if the process is |
144 * non-interactive. | 154 * non-interactive. |
145 */ | 155 */ |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 /** | 298 /** |
289 * Contains the system message for the process exception if any. | 299 * Contains the system message for the process exception if any. |
290 */ | 300 */ |
291 final String message; | 301 final String message; |
292 | 302 |
293 /** | 303 /** |
294 * Contains the OS error code for the process exception if any. | 304 * Contains the OS error code for the process exception if any. |
295 */ | 305 */ |
296 final int errorCode; | 306 final int errorCode; |
297 } | 307 } |
OLD | NEW |