Build 1.0_r1(from source)

java.lang
Class ProcessBuilder

java.lang.Object
  extended by java.lang.ProcessBuilder

public final class ProcessBuilder
extends Object

A builder for creating OS-specific processes.

Since:
1.5

Constructor Summary
ProcessBuilder(List<String> command)
           Constructs an instance with the given command.
ProcessBuilder(String... command)
           Constructs an instance with the given command.
 
Method Summary
 List<String> command()
           The builder's current program and arguments.
 ProcessBuilder command(List<String> command)
           Changes the program and arguments to the command given.
 ProcessBuilder command(String... command)
           Changes the program and arguments to the command given.
 File directory()
           The working directory that's currently set.
 ProcessBuilder directory(File directory)
           Changes the working directory to the directory given.
 Map<String,String> environment()
           The builder's current environment.
 boolean redirectErrorStream()
           Indicates whether or not the standard error should be redirected to standard output.
 ProcessBuilder redirectErrorStream(boolean redirectErrorStream)
           Changes the state of whether or not standard error is redirected.
 Process start()
           Starts a new process based on the current state of the builder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProcessBuilder

public ProcessBuilder(String... command)

Constructs an instance with the given command.

Parameters:
command - The program and arguments.

ProcessBuilder

public ProcessBuilder(List<String> command)

Constructs an instance with the given command.

Parameters:
command - The program and arguments.
Throws:
NullPointerException - if command is null.
Method Detail

command

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.

command

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.

command

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.

directory

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.

directory

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.

environment

public Map<String,String> environment()

The builder's current environment. When an instance is created, the environment is populated with a copy of the environment, as returned by System.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.

redirectErrorStream

public boolean redirectErrorStream()

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

Returns:
Indicates whether or not standard error is redirected.

redirectErrorStream

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.

start

public Process start()
              throws IOException

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 SecurityManager.checkExec(String) doesn't allow process creation.
IOException - if an I/O error happens.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature