Dart API Referencedart:ioProcess

Process class

Process is used to start new processes using the static start and run methods.

class Process {
  /**
   * Starts a process running the [executable] with the specified
   * [arguments]. Returns a [:Future<Process>:] that completes with a
   * Process instance when the process has been successfully
   * started. That [Process] object can be used to interact with the
   * process. If the process cannot be started the returned [Future]
   * completes with an exception.
   *
   * An optional [ProcessOptions] object can be passed to specify
   * options other than the executable and the arguments.
   */
  static Future<Process> start(String executable,
                               List<String> arguments,
                               [ProcessOptions options]) {
    return _Process.start(executable, arguments, options);
  }

  /**
   * Starts a process and runs it non-interactively to completion. The
   * process run is [executable] with the specified [arguments].
   *
   * An optional [ProcessOptions] object can be passed to specify
   * options other than the executable and the arguments.
   *
   * Returns a [:Future<ProcessResult>:] that completes with the
   * result of running the process, i.e., exit code, standard out and
   * standard in.
   */
  static Future<ProcessResult> run(String executable,
                                   List<String> arguments,
                                   [ProcessOptions options]) {
    return _Process.run(executable, arguments, options);
  }

  /**
   * Returns an input stream of the process stdout.
   *
   * Throws an [UnsupportedOperationException] if the process is
   * non-interactive.
   */
  abstract InputStream get stdout;

  /**
   * Returns an input stream of the process stderr.
   *
   * Throws an [UnsupportedOperationException] if the process is
   * non-interactive.
   */
  abstract InputStream get stderr;

  /**
   * Returns an output stream to the process stdin.
   *
   * Throws an [UnsupportedOperationException] if the process is
   * non-interactive.
   */
  abstract OutputStream get stdin;

  /**
   * Sets an exit handler which gets invoked when the process
   * terminates.
   *
   * Throws an [UnsupportedOperationException] if the process is
   * non-interactive.
   */
  abstract void set onExit(void callback(int exitCode));

  /**
   * On Windows, [kill] kills the process, ignoring the [signal]
   * flag. On Posix systems, [kill] sends [signal] to the
   * process. Depending on the signal giving, it'll have different
   * meanings. When the process terminates as a result of calling
   * [kill] [onExit] is called.
   *
   * Returns [:true:] if the process is successfully killed (the
   * signal is successfully sent). Returns [:false:] if the process
   * could not be killed (the signal could not be sent). Usually,
   * a [:false:] return value from kill means that the process is
   * already dead.
   */
  abstract bool kill([ProcessSignal signal = ProcessSignal.SIGTERM]);

  /**
   * Terminates the streams of a process. [close] must be called on a
   * process to free the system resources associated with it if not all
   * data on the stdout and stderr streams have been read. Usually,
   * close should be called in [onExit], but care must be taken to actually
   * wait on the stderr and stdout streams to close if all data is required.
   * Once a process has been closed it can no longer be killed and [onExit]
   * is detached so the application is not notified of process termination.
   */
  abstract void close();
}

Static Methods

Future<Process> start(String executable, List<String> arguments, [ProcessOptions options]) #

Starts a process running the executable with the specified arguments. Returns a Future<Process> that completes with a Process instance when the process has been successfully started. That Process object can be used to interact with the process. If the process cannot be started the returned Future completes with an exception.

An optional ProcessOptions object can be passed to specify options other than the executable and the arguments.

static Future<Process> start(String executable,
                             List<String> arguments,
                             [ProcessOptions options]) {
  return _Process.start(executable, arguments, options);
}

Future<ProcessResult> run(String executable, List<String> arguments, [ProcessOptions options]) #

Starts a process and runs it non-interactively to completion. The process run is executable with the specified arguments.

An optional ProcessOptions object can be passed to specify options other than the executable and the arguments.

Returns a Future<ProcessResult> that completes with the result of running the process, i.e., exit code, standard out and standard in.

static Future<ProcessResult> run(String executable,
                                 List<String> arguments,
                                 [ProcessOptions options]) {
  return _Process.run(executable, arguments, options);
}

Properties

abstract void set onExit(void callback(int exitCode)) #

Sets an exit handler which gets invoked when the process terminates.

Throws an UnsupportedOperationException if the process is non-interactive.

final InputStream stderr #

Returns an input stream of the process stderr.

Throws an UnsupportedOperationException if the process is non-interactive.

abstract InputStream get stderr;

final OutputStream stdin #

Returns an output stream to the process stdin.

Throws an UnsupportedOperationException if the process is non-interactive.

abstract OutputStream get stdin;

final InputStream stdout #

Returns an input stream of the process stdout.

Throws an UnsupportedOperationException if the process is non-interactive.

abstract InputStream get stdout;

Methods

abstract void close() #

Terminates the streams of a process. close must be called on a process to free the system resources associated with it if not all data on the stdout and stderr streams have been read. Usually, close should be called in onExit, but care must be taken to actually wait on the stderr and stdout streams to close if all data is required. Once a process has been closed it can no longer be killed and onExit is detached so the application is not notified of process termination.

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

On Windows, kill kills the process, ignoring the signal flag. On Posix systems, kill sends signal to the process. Depending on the signal giving, it'll have different meanings. When the process terminates as a result of calling [kill] [onExit] is called.

Returns true if the process is successfully killed (the signal is successfully sent). Returns false if the process could not be killed (the signal could not be sent). Usually, a false return value from kill means that the process is already dead.