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

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

Issue 798743004: Add support for starting a detached process (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 5 years, 11 months 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 * Use [environment] to set the environment variables for the process. If not 234 * Use [environment] to set the environment variables for the process. If not
235 * set the environment of the parent process is inherited. Currently, only 235 * set the environment of the parent process is inherited. Currently, only
236 * US-ASCII environment variables are supported and errors are likely to occur 236 * US-ASCII environment variables are supported and errors are likely to occur
237 * if an environment variable with code-points outside the US-ASCII range is 237 * if an environment variable with code-points outside the US-ASCII range is
238 * passed in. 238 * passed in.
239 * 239 *
240 * If [includeParentEnvironment] is `true`, the process's environment will 240 * If [includeParentEnvironment] is `true`, the process's environment will
241 * include the parent process's environment, with [environment] taking 241 * include the parent process's environment, with [environment] taking
242 * precedence. Default is `true`. 242 * precedence. Default is `true`.
243 * 243 *
244 * If [runInShell] is true, the process will be spawned through a system 244 * If [runInShell] is `true`, the process will be spawned through a system
245 * shell. On Linux and Mac OS, [:/bin/sh:] is used, while 245 * shell. On Linux and Mac OS, [:/bin/sh:] is used, while
246 * [:%WINDIR%\system32\cmd.exe:] is used on Windows. 246 * [:%WINDIR%\system32\cmd.exe:] is used on Windows.
247 * 247 *
248 * Users must read all data coming on the [stdout] and [stderr] 248 * Users must read all data coming on the [stdout] and [stderr]
249 * streams of processes started with [:Process.start:]. If the user 249 * streams of processes started with [:Process.start:]. If the user
250 * does not read all data on the streams the underlying system 250 * does not read all data on the streams the underlying system
251 * resources will not be freed since there is still pending data. 251 * resources will not be freed since there is still pending data.
252 * 252 *
253 * The following code uses `Process.start` to grep for `main` in the 253 * The following code uses `Process.start` to grep for `main` in the
254 * file `test.dart` on Linux. 254 * file `test.dart` on Linux.
255 * 255 *
256 * Process.start('grep', ['-i', 'main', 'test.dart']).then((process) { 256 * Process.start('grep', ['-i', 'main', 'test.dart']).then((process) {
257 * stdout.addStream(process.stdout); 257 * stdout.addStream(process.stdout);
258 * stderr.addStream(process.stderr); 258 * stderr.addStream(process.stderr);
259 * }); 259 * });
260 *
261 * If [detach] is `true` a detached process will be created. A
262 * detached process has no connection to its parent, and can
263 * keep running on its own when the parent dies. The only
264 * information available from a detached process is its `pid`. There
265 * is no connection to its `stdin`, `stdout` or `stderr` nor will its
266 * exit code become available when it terminates.
260 */ 267 */
261 external static Future<Process> start( 268 external static Future<Process> start(
262 String executable, 269 String executable,
263 List<String> arguments, 270 List<String> arguments,
264 {String workingDirectory, 271 {String workingDirectory,
265 Map<String, String> environment, 272 Map<String, String> environment,
266 bool includeParentEnvironment: true, 273 bool includeParentEnvironment: true,
267 bool runInShell: false}); 274 bool runInShell: false,
275 bool detach: false});
268 276
269 /** 277 /**
270 * Starts a process and runs it non-interactively to completion. The 278 * Starts a process and runs it non-interactively to completion. The
271 * process run is [executable] with the specified [arguments]. 279 * process run is [executable] with the specified [arguments].
272 * 280 *
273 * Use [workingDirectory] to set the working directory for the process. Note 281 * Use [workingDirectory] to set the working directory for the process. Note
274 * that the change of directory occurs before executing the process on some 282 * that the change of directory occurs before executing the process on some
275 * platforms, which may have impact when using relative paths for the 283 * platforms, which may have impact when using relative paths for the
276 * executable and the arguments. 284 * executable and the arguments.
277 * 285 *
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 final int errorCode; 521 final int errorCode;
514 522
515 const ProcessException(this.executable, this.arguments, [this.message = "", 523 const ProcessException(this.executable, this.arguments, [this.message = "",
516 this.errorCode = 0]); 524 this.errorCode = 0]);
517 String toString() { 525 String toString() {
518 var msg = (message == null) ? 'OS error code: $errorCode' : message; 526 var msg = (message == null) ? 'OS error code: $errorCode' : message;
519 var args = arguments.join(' '); 527 var args = arguments.join(' ');
520 return "ProcessException: $msg\n Command: $executable $args"; 528 return "ProcessException: $msg\n Command: $executable $args";
521 } 529 }
522 } 530 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/io_patch.dart ('k') | tests/standalone/io/process_detached_script.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698