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

Side by Side Diff: runtime/bin/process_impl.dart

Issue 10202014: Fix exception throwing in connection with process starting. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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
« 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 class _ProcessStartStatus { 5 class _ProcessStartStatus {
6 int _errorCode; // Set to OS error code if process start failed. 6 int _errorCode; // Set to OS error code if process start failed.
7 String _errorMessage; // Set to OS error message if process start failed. 7 String _errorMessage; // Set to OS error message if process start failed.
8 } 8 }
9 9
10 10
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 Function _onError; 311 Function _onError;
312 Function _onStart; 312 Function _onStart;
313 } 313 }
314 314
315 315
316 // _NonInteractiveProcess is a wrapper around an interactive process 316 // _NonInteractiveProcess is a wrapper around an interactive process
317 // that restricts the interface to disallow access to the streams and 317 // that restricts the interface to disallow access to the streams and
318 // buffers output so it can be delivered to the callback when the 318 // buffers output so it can be delivered to the callback when the
319 // process exits. 319 // process exits.
320 class _NonInteractiveProcess implements Process { 320 class _NonInteractiveProcess implements Process {
321
322 _NonInteractiveProcess.start(String path, 321 _NonInteractiveProcess.start(String path,
323 List<String> arguments, 322 List<String> arguments,
324 ProcessOptions options, 323 ProcessOptions options,
325 Function this._callback) { 324 Function this._callback) {
326 _process = new _InteractiveProcess.start(path, arguments, options); 325 // Extract output encoding options and verify arguments.
327
328 // Setup process exit handling.
329 _process.onExit = (exitCode) {
330 _exitCode = exitCode;
331 _checkDone();
332 };
333
334 // Extract output encoding options.
335 var stdoutEncoding = Encoding.UTF_8; 326 var stdoutEncoding = Encoding.UTF_8;
336 var stderrEncoding = Encoding.UTF_8; 327 var stderrEncoding = Encoding.UTF_8;
337 if (options !== null) { 328 if (options !== null) {
338 if (options.stdoutEncoding !== null) { 329 if (options.stdoutEncoding !== null) {
339 stdoutEncoding = options.stdoutEncoding; 330 stdoutEncoding = options.stdoutEncoding;
340 if (stdoutEncoding is !Encoding) { 331 if (stdoutEncoding is !Encoding) {
341 throw new IllegalArgumentException( 332 throw new IllegalArgumentException(
342 'stdoutEncoding option is not an encoding: $stdoutEncoding'); 333 'stdoutEncoding option is not an encoding: $stdoutEncoding');
343 } 334 }
344 } 335 }
345 if (options.stderrEncoding !== null) { 336 if (options.stderrEncoding !== null) {
346 stderrEncoding = options.stderrEncoding; 337 stderrEncoding = options.stderrEncoding;
347 if (stderrEncoding is !Encoding) { 338 if (stderrEncoding is !Encoding) {
348 throw new IllegalArgumentException( 339 throw new IllegalArgumentException(
349 'stderrEncoding option is not an encoding: $stderrEncoding'); 340 'stderrEncoding option is not an encoding: $stderrEncoding');
350 } 341 }
351 } 342 }
352 } 343 }
353 344
345 // Start the underlying process.
346 _process = new _InteractiveProcess.start(path, arguments, options);
347
348 // Setup process exit handling.
349 _process.onExit = (exitCode) {
350 _exitCode = exitCode;
351 _checkDone();
352 };
353
354 // Setup stdout handling. 354 // Setup stdout handling.
355 _stdoutBuffer = new StringBuffer(); 355 _stdoutBuffer = new StringBuffer();
356 var stdoutStream = new StringInputStream(_process.stdout, stdoutEncoding); 356 var stdoutStream = new StringInputStream(_process.stdout, stdoutEncoding);
357 stdoutStream.onData = () { 357 stdoutStream.onData = () {
358 var data = stdoutStream.read(); 358 var data = stdoutStream.read();
359 if (data != null) _stdoutBuffer.add(data); 359 if (data != null) _stdoutBuffer.add(data);
360 }; 360 };
361 stdoutStream.onClosed = () { 361 stdoutStream.onClosed = () {
362 _stdoutClosed = true; 362 _stdoutClosed = true;
363 _checkDone(); 363 _checkDone();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 void close() => _process.close(); 420 void close() => _process.close();
421 421
422 Process _process; 422 Process _process;
423 Function _callback; 423 Function _callback;
424 StringBuffer _stdoutBuffer; 424 StringBuffer _stdoutBuffer;
425 StringBuffer _stderrBuffer; 425 StringBuffer _stderrBuffer;
426 int _exitCode; 426 int _exitCode;
427 bool _stdoutClosed = false; 427 bool _stdoutClosed = false;
428 bool _stderrClosed = false; 428 bool _stderrClosed = false;
429 } 429 }
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