Skip to content

Most visited

Recently visited

navigation
Added in API level 1

ProcessBuilder

public final class ProcessBuilder
extends Object

java.lang.Object
   ↳ java.lang.ProcessBuilder


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.

Inherited methods

From class java.lang.Object

Public constructors

ProcessBuilder

Added in API level 1
ProcessBuilder (String... command)

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.

ProcessBuilder

Added in API level 1
ProcessBuilder (List<String> command)

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

command

Added in API level 1
ProcessBuilder command (List<String> command)

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.

command

Added in API level 1
List<String> command ()

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.

command

Added in API level 1
ProcessBuilder command (String... command)

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.

directory

Added in API level 1
ProcessBuilder directory (File directory)

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.

directory

Added in API level 1
File directory ()

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.

environment

Added in API level 1
Map<StringString> environment ()

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.

redirectErrorStream

Added in API level 1
ProcessBuilder redirectErrorStream (boolean redirectErrorStream)

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.

redirectErrorStream

Added in API level 1
boolean redirectErrorStream ()

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.

start

Added in API level 1
Process start ()

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.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.