Android APIs
public final class

ProcessBuilder

extends Object
java.lang.Object
   ↳ java.lang.ProcessBuilder

Class Overview

Creates operating system processes. See Process for documentation and example usage.

Summary

Public Constructors
ProcessBuilder(String... command)
Constructs a new ProcessBuilder instance with the specified operating system program and its arguments.
ProcessBuilder(List<String> command)
Constructs a new ProcessBuilder instance with the specified operating system program and its arguments.
Public Methods
ProcessBuilder command(List<String> command)
Changes the program and arguments of this process builder.
List<String> command()
Returns this process builder's current program and arguments.
ProcessBuilder command(String... command)
Changes the program and arguments of this process builder.
ProcessBuilder directory(File directory)
Changes the working directory of this process builder.
File directory()
Returns the working directory of this process builder.
Map<StringString> environment()
Returns this process builder's current environment.
ProcessBuilder redirectErrorStream(boolean redirectErrorStream)
Changes the state of whether or not standard error is redirected to standard output.
boolean redirectErrorStream()
Indicates whether the standard error should be redirected to standard output.
Process start()
Starts a new process based on the current state of this process builder.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ProcessBuilder (String... command)

Added in API level 1

Constructs a new ProcessBuilder instance with the specified operating system program and its arguments.

Parameters
command String: the requested operating system program and its arguments.

public ProcessBuilder (List<String> command)

Added in API level 1

Constructs a new ProcessBuilder instance with the specified operating system program and its arguments. Note that the list passed to this constructor is not copied, so any subsequent updates to it are reflected in this instance's state.

Parameters
command List: the requested operating system program and its arguments.
Throws
NullPointerException if command is null.

Public Methods

public ProcessBuilder command (List<String> command)

Added in API level 1

Changes the program and arguments of this process builder. Note that the list passed to this method is not copied, so any subsequent updates to it are reflected in this instance's state.

Parameters
command List: the new operating system program and its arguments.
Returns
ProcessBuilder this process builder instance.
Throws
NullPointerException if command is null.

public List<String> command ()

Added in API level 1

Returns this process builder's current program and arguments. Note that the returned list is not a copy and modifications to it will change the state of this instance.

Returns
List<String> this process builder's program and arguments.

public ProcessBuilder command (String... command)

Added in API level 1

Changes the program and arguments of this process builder.

Parameters
command String: the new operating system program and its arguments.
Returns
ProcessBuilder this process builder instance.

public ProcessBuilder directory (File directory)

Added in API level 1

Changes the working directory of this process builder. If the specified directory is null, then the working directory of the Java process is used when a process is started.

Parameters
directory File: the new working directory for this process builder.
Returns
ProcessBuilder this process builder instance.

public File directory ()

Added in API level 1

Returns the working directory of this process builder. If null is returned, then the working directory of the Java process is used when a process is started.

Returns
File the current working directory, may be null.

public Map<StringString> environment ()

Added in API level 1

Returns this process builder's current environment. When a process builder instance is created, the environment is populated with a copy of the environment, as returned by getenv(). Note that the map returned by this method is not a copy and any changes made to it are reflected in this instance's state.

Returns
Map<StringString> the map containing this process builder's environment variables.

public ProcessBuilder redirectErrorStream (boolean redirectErrorStream)

Added in API level 1

Changes the state of whether or not standard error is redirected to standard output.

Parameters
redirectErrorStream boolean: true to redirect standard error, false otherwise.
Returns
ProcessBuilder this process builder instance.

public boolean redirectErrorStream ()

Added in API level 1

Indicates whether the standard error should be redirected to standard output. If redirected, the getErrorStream() will always return end of stream and standard error is written to getInputStream().

Returns
boolean true if the standard error is redirected; false otherwise.

public Process start ()

Added in API level 1

Starts a new process based on the current state of this process builder.

Returns
Process the new Process instance.
Throws
NullPointerException if any of the elements of command() is null.
IndexOutOfBoundsException if command() is empty.
IOException if an I/O error happens.