Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Side by Side Diff: sdk/lib/io/process.dart

Issue 94573002: Improve the documentation for exit codes in Process (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor update Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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);
11 external static void _setExitCode(int status); 11 external static void _setExitCode(int status);
12 external static void _sleep(int millis); 12 external static void _sleep(int millis);
13 external static int _pid(Process process); 13 external static int _pid(Process process);
14 } 14 }
15 15
16 /** 16 /**
17 * Exit the Dart VM process immediately with the given [status] code. 17 * Exit the Dart VM process immediately with the given [exitCode] exit
ahe 2013/11/28 14:27:23 I think it is problematic to use the word exitCode
Søren Gjesse 2013/11/29 10:29:25 Renamed argument to code..
18 * code.
18 * 19 *
19 * This does not wait for any asynchronous operations to terminate. Using 20 * This does not wait for any asynchronous operations to terminate. Using
20 * [exit] is therefore very likely to lose data. 21 * [exit] is therefore very likely to lose data.
22 *
23 * The handling of exit codes is platform specific.
24 *
25 * On Linux and Mac OS an exit code for normal termination will always
26 * be in the range [0..255]. If an exit code outside this range is
27 * set the actual exit code will be the lower 8 bits masked off and
28 * treated as an unsigned value. E.g. using an exit code of -1 will
29 * result in a actual exit code of 255 being reported.
30 *
31 * On Windows the exit code can be set to any 32-bit value. However
32 * some of these values are reserved for reporting system errors like
33 * crashes.
34 *
35 * Besides this the Dart executable itself uses an exit code of `254`
36 * for reporting compile time errors and an exit code of `255` for
37 * reporting runtime error (unhandled exception).
38 *
39 * Due to these facts it is recommended to only use exit codes in the
40 * range [0..127] for communicating the result of running a Dart
41 * program to the surrounding environment. This will avoid any
42 * cross-platform issues.
21 */ 43 */
22 void exit(int status) { 44 void exit(int exitCode) {
23 if (status is !int) { 45 if (status is !int) {
24 throw new ArgumentError("exit: int status expected"); 46 throw new ArgumentError("exit: int status expected");
25 } 47 }
26 _ProcessUtils._exit(status); 48 _ProcessUtils._exit(status);
27 } 49 }
28 50
29 /** 51 /**
30 * Global exit code for the Dart VM. 52 * Global exit code for the Dart VM.
31 * 53 *
32 * The exit code is global for the Dart VM and the last assignment to 54 * The exit code is global for the Dart VM and the last assignment to
33 * exitCode from any isolate determines the exit code of the Dart VM 55 * exitCode from any isolate determines the exit code of the Dart VM
34 * on normal termination. 56 * on normal termination.
57 *
58 * See [exit] for more information on how to chose a value for the
59 * exit code.
35 */ 60 */
36 set exitCode(int status) { 61 set exitCode(int exitCode) {
ahe 2013/11/28 14:27:23 Even more troubling here :-)
Søren Gjesse 2013/11/29 10:29:25 Renamed to code here as well.
37 if (status is !int) { 62 if (status is !int) {
38 throw new ArgumentError("setExitCode: int status expected"); 63 throw new ArgumentError("setExitCode: int status expected");
39 } 64 }
40 _ProcessUtils._setExitCode(status); 65 _ProcessUtils._setExitCode(status);
41 } 66 }
42 67
43 /** 68 /**
44 * Sleep for the duration specified in [duration]. 69 * Sleep for the duration specified in [duration].
45 * 70 *
46 * Use this with care, as no asynchronous operations can be processed 71 * Use this with care, as no asynchronous operations can be processed
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 List<String> arguments, 203 List<String> arguments,
179 {String workingDirectory, 204 {String workingDirectory,
180 Map<String, String> environment, 205 Map<String, String> environment,
181 bool includeParentEnvironment: true, 206 bool includeParentEnvironment: true,
182 bool runInShell: false, 207 bool runInShell: false,
183 Encoding stdoutEncoding: SYSTEM_ENCODING, 208 Encoding stdoutEncoding: SYSTEM_ENCODING,
184 Encoding stderrEncoding: SYSTEM_ENCODING}); 209 Encoding stderrEncoding: SYSTEM_ENCODING});
185 210
186 /** 211 /**
187 * Returns the standard output stream of the process as a [:Stream:]. 212 * Returns the standard output stream of the process as a [:Stream:].
188 *
189 * Throws an [UnsupportedError] if the process is
190 * non-interactive.
191 */ 213 */
192 Stream<List<int>> get stdout; 214 Stream<List<int>> get stdout;
193 215
194 /** 216 /**
195 * Returns the standard error stream of the process as a [:Stream:]. 217 * Returns the standard error stream of the process as a [:Stream:].
196 *
197 * Throws an [UnsupportedError] if the process is
198 * non-interactive.
199 */ 218 */
200 Stream<List<int>> get stderr; 219 Stream<List<int>> get stderr;
201 220
202 /** 221 /**
203 * Returns the standard input stream of the process as an [IOSink]. 222 * Returns the standard input stream of the process as an [IOSink].
204 *
205 * Throws an [UnsupportedError] if the process is
206 * non-interactive.
207 */ 223 */
208 IOSink get stdin; 224 IOSink get stdin;
209 225
210 /** 226 /**
211 * Returns the process id of the process. 227 * Returns the process id of the process.
212 */ 228 */
213 int get pid; 229 int get pid;
214 230
215 /** 231 /**
216 * Returns a [:Future:] which completes with the exit code of the process 232 * Returns a [:Future:] which completes with the exit code of the process
217 * when the process completes. 233 * when the process completes.
218 * 234 *
219 * Throws an [UnsupportedError] if the process is 235 * The handling of exit codes is platform specific.
220 * non-interactive. 236 *
237 * On Linux and Mac a normal exit code will be a positive value in
238 * the range [0..255]. If the process was terminated due to a signal
239 * the exit code will be a negative value in the range [-255..0],
ahe 2013/11/28 14:27:23 Does 0 mean that it crashed or not?
Søren Gjesse 2013/11/29 10:29:25 0 should not have been in the range. Changed to [-
240 * where the absolute value of the exit code is the signal
241 * number. E.g. if a process crashes due to a segmentation violation
242 * the exit code will be -11 as the signal SIGSEGV has the number
243 * 11.
244 *
245 * On Windows a process can report any 32-bit value as an exit
246 * code. When returning the exit code this exit code is turned into
247 * a signed value. Some special values are used to report
248 * termination due to some system event. E.g. if a process crashes
249 * due to an access violation the 32-bit exit code is `0xc0000005`,
250 * which will be returned as the negative number `-1073741819`. To
251 * get the original 32-bit value use `(0x100000000 + exitCode) &
252 * 0xffffffff`.
ahe 2013/11/28 14:27:23 I would argue that the VM should perform this comp
Søren Gjesse 2013/11/29 10:29:25 I did make the change https://codereview.chromium.
221 */ 253 */
222 Future<int> exitCode; 254 Future<int> exitCode;
223 255
224 /** 256 /**
225 * On Windows, [kill] kills the process, ignoring the [signal] 257 * On Windows, [kill] kills the process, ignoring the [signal]
226 * flag. On Posix systems, [kill] sends [signal] to the 258 * flag. On Posix systems, [kill] sends [signal] to the
227 * process. Depending on the signal giving, it'll have different 259 * process. Depending on the signal giving, it'll have different
228 * meanings. When the process terminates as a result of calling 260 * meanings. When the process terminates as a result of calling
229 * [kill] [onExit] is called. 261 * [kill] [onExit] is called.
230 * 262 *
231 * Returns [:true:] if the process is successfully killed (the 263 * Returns [:true:] if the process is successfully killed (the
232 * signal is successfully sent). Returns [:false:] if the process 264 * signal is successfully sent). Returns [:false:] if the process
233 * could not be killed (the signal could not be sent). Usually, 265 * could not be killed (the signal could not be sent). Usually,
234 * a [:false:] return value from kill means that the process is 266 * a [:false:] return value from kill means that the process is
235 * already dead. 267 * already dead.
236 */ 268 */
237 bool kill([ProcessSignal signal = ProcessSignal.SIGTERM]); 269 bool kill([ProcessSignal signal = ProcessSignal.SIGTERM]);
238 } 270 }
239 271
240 272
241 /** 273 /**
242 * [ProcessResult] represents the result of running a non-interactive 274 * [ProcessResult] represents the result of running a non-interactive
243 * process started with [:Process.run:]. 275 * process started with [:Process.run:].
244 */ 276 */
245 abstract class ProcessResult { 277 abstract class ProcessResult {
246 /** 278 /**
247 * Exit code for the process. 279 * Exit code for the process.
280 *
281 * See [Process.exitCode] for more information in the exit code
282 * value.
248 */ 283 */
249 int get exitCode; 284 int get exitCode;
250 285
251 /** 286 /**
252 * Standard output from the process. The value used for the 287 * Standard output from the process. The value used for the
253 * `stdoutEncoding` argument to `Process.run` determins the type. If 288 * `stdoutEncoding` argument to `Process.run` determins the type. If
254 * `null` was used this value is of type `List<int> otherwise it is 289 * `null` was used this value is of type `List<int> otherwise it is
255 * of type `String`. 290 * of type `String`.
256 */ 291 */
257 get stdout; 292 get stdout;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 /** 369 /**
335 * Contains the system message for the process exception if any. 370 * Contains the system message for the process exception if any.
336 */ 371 */
337 final String message; 372 final String message;
338 373
339 /** 374 /**
340 * Contains the OS error code for the process exception if any. 375 * Contains the OS error code for the process exception if any.
341 */ 376 */
342 final int errorCode; 377 final int errorCode;
343 } 378 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698