加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090328121002/http://developer.android.com:80/reference/java/lang/ProcessBuilder.html
public final class

ProcessBuilder

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

Class Overview

A builder for creating OS-specific processes.

Summary

Public Constructors
ProcessBuilder(String... command)

Constructs an instance with the given command.

ProcessBuilder(List<String> command)

Constructs an instance with the given command.

Public Methods
ProcessBuilder command(String... command)

Changes the program and arguments to the command given.

ProcessBuilder command(List<String> command)

Changes the program and arguments to the command given.

List<String> command()

The builder's current program and arguments.

ProcessBuilder directory(File directory)

Changes the working directory to the directory given.

File directory()

The working directory that's currently set.

Map<StringString> environment()

The builder's current environment.

ProcessBuilder redirectErrorStream(boolean redirectErrorStream)

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

boolean redirectErrorStream()

Indicates whether or not the standard error should be redirected to standard output.

Process start()

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

[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ProcessBuilder (String... command)

Constructs an instance with the given command.

Parameters
command The program and arguments.

public ProcessBuilder (List<String> command)

Constructs an instance with the given command.

Parameters
command The program and arguments.
Throws
NullPointerException if command is null.

Public Methods

public ProcessBuilder command (String... command)

Changes the program and arguments to the command given.

Parameters
command The program and arguments.
Returns
  • A reference to this instance.

public ProcessBuilder command (List<String> command)

Changes the program and arguments to the command given. The list passed is not copied, so any subsequent updates to it are reflected in this instance's state.

Parameters
command The program and arguments.
Returns
  • A reference to this instance.
Throws
NullPointerException if command is null.

public List<String> command ()

The builder's current program and arguments. The returned value is considered live and modifications to it will change the state of the instance.

Returns
  • The program and arguments currently set.

public ProcessBuilder directory (File directory)

Changes the working directory to the directory given. If the given directory is null, then the working directory of the Java process is used when a process is started.

Parameters
directory The working directory to set.
Returns
  • A reference to this instance.

public File directory ()

The working directory that's currently set. If this value is null, then the working directory of the Java process is used.

Returns
  • The current working directory, which may be null.

public Map<StringString> environment ()

The builder's current environment. When an instance is created, the environment is populated with a copy of the environment, as returned by getenv(). The Map returned is live and any changes made to it are reflected in this instance's state.

Returns
  • The Map of the current environment variables.

public ProcessBuilder redirectErrorStream (boolean redirectErrorStream)

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

Parameters
redirectErrorStream true to redirect standard error, false if not.
Returns
  • A reference to this instance.

public boolean redirectErrorStream ()

Indicates whether or not 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
  • Indicates whether or not standard error is redirected.

public Process start ()

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

Returns
  • The new process that was started.
Throws
NullPointerException if any of the elements of command() are null.
IndexOutOfBoundsException if command() is empty.
SecurityException if checkExec(String) doesn't allow process creation.
IOException if an I/O error happens.