Dart DocumentationioPubProcess

PubProcess class

A wrapper around Process that exposes dart:async-style APIs.

class PubProcess {
 /// The underlying `dart:io` [Process].
 final Process _process;

 /// The mutable field for [stdin].
 EventSink<List<int>> _stdin;

 /// The mutable field for [stdinClosed].
 Future _stdinClosed;

 /// The mutable field for [stdout].
 ByteStream _stdout;

 /// The mutable field for [stderr].
 ByteStream _stderr;

 /// The mutable field for [exitCode].
 Future<int> _exitCode;

 /// The sink used for passing data to the process's standard input stream.
 /// Errors on this stream are surfaced through [stdinClosed], [stdout],
 /// [stderr], and [exitCode], which are all members of an [ErrorGroup].
 EventSink<List<int>> get stdin => _stdin;

 // TODO(nweiz): write some more sophisticated Future machinery so that this
 // doesn't surface errors from the other streams/futures, but still passes its
 // unhandled errors to them. Right now it's impossible to recover from a stdin
 // error and continue interacting with the process.
 /// A [Future] that completes when [stdin] is closed, either by the user or by
 /// the process itself.
 ///
 /// This is in an [ErrorGroup] with [stdout], [stderr], and [exitCode], so any
 /// error in process will be passed to it, but won't reach the top-level error
 /// handler unless nothing has handled it.
 Future get stdinClosed => _stdinClosed;

 /// The process's standard output stream.
 ///
 /// This is in an [ErrorGroup] with [stdinClosed], [stderr], and [exitCode],
 /// so any error in process will be passed to it, but won't reach the
 /// top-level error handler unless nothing has handled it.
 ByteStream get stdout => _stdout;

 /// The process's standard error stream.
 ///
 /// This is in an [ErrorGroup] with [stdinClosed], [stdout], and [exitCode],
 /// so any error in process will be passed to it, but won't reach the
 /// top-level error handler unless nothing has handled it.
 ByteStream get stderr => _stderr;

 /// A [Future] that will complete to the process's exit code once the process
 /// has finished running.
 ///
 /// This is in an [ErrorGroup] with [stdinClosed], [stdout], and [stderr], so
 /// any error in process will be passed to it, but won't reach the top-level
 /// error handler unless nothing has handled it.
 Future<int> get exitCode => _exitCode;

 /// Creates a new [PubProcess] wrapping [process].
 PubProcess(Process process)
   : _process = process {
   var errorGroup = new ErrorGroup();

   var pair = consumerToSink(process.stdin);
   _stdin = pair.first;
   _stdinClosed = errorGroup.registerFuture(pair.last);

   _stdout = new ByteStream(
       errorGroup.registerStream(process.stdout));
   _stderr = new ByteStream(
       errorGroup.registerStream(process.stderr));

   var exitCodeCompleter = new Completer();
   _exitCode = errorGroup.registerFuture(exitCodeCompleter.future);
   _process.exitCode.then((code) => exitCodeCompleter.complete(code));
 }

 /// Sends [signal] to the underlying process.
 bool kill([ProcessSignal signal = ProcessSignal.SIGTERM]) =>
   _process.kill(signal);
}

Constructors

new PubProcess(Process process) #

Creates a new PubProcess wrapping process.

PubProcess(Process process)
 : _process = process {
 var errorGroup = new ErrorGroup();

 var pair = consumerToSink(process.stdin);
 _stdin = pair.first;
 _stdinClosed = errorGroup.registerFuture(pair.last);

 _stdout = new ByteStream(
     errorGroup.registerStream(process.stdout));
 _stderr = new ByteStream(
     errorGroup.registerStream(process.stderr));

 var exitCodeCompleter = new Completer();
 _exitCode = errorGroup.registerFuture(exitCodeCompleter.future);
 _process.exitCode.then((code) => exitCodeCompleter.complete(code));
}

Properties

final Future<int> exitCode #

A Future that will complete to the process's exit code once the process has finished running.

This is in an ErrorGroup with stdinClosed, stdout, and stderr, so any error in process will be passed to it, but won't reach the top-level error handler unless nothing has handled it.

Future<int> get exitCode => _exitCode;

final ByteStream stderr #

The process's standard error stream.

This is in an ErrorGroup with stdinClosed, stdout, and exitCode, so any error in process will be passed to it, but won't reach the top-level error handler unless nothing has handled it.

ByteStream get stderr => _stderr;

final EventSink<List<int>> stdin #

The sink used for passing data to the process's standard input stream. Errors on this stream are surfaced through stdinClosed, stdout, stderr, and exitCode, which are all members of an ErrorGroup.

EventSink<List<int>> get stdin => _stdin;

final Future stdinClosed #

A Future that completes when stdin is closed, either by the user or by the process itself.

This is in an ErrorGroup with stdout, stderr, and exitCode, so any error in process will be passed to it, but won't reach the top-level error handler unless nothing has handled it.

Future get stdinClosed => _stdinClosed;

final ByteStream stdout #

The process's standard output stream.

This is in an ErrorGroup with stdinClosed, stderr, and exitCode, so any error in process will be passed to it, but won't reach the top-level error handler unless nothing has handled it.

ByteStream get stdout => _stdout;

Methods

bool kill([ProcessSignal signal = ProcessSignal.SIGTERM]) #

Sends signal to the underlying process.

bool kill([ProcessSignal signal = ProcessSignal.SIGTERM]) =>
 _process.kill(signal);