Constructor and Description |
---|
ProcessBuilder(List<String> command)
Constructs a new
ProcessBuilder instance with the specified
operating system program and its arguments. |
ProcessBuilder(String... command)
Constructs a new
ProcessBuilder instance with the specified
operating system program and its arguments. |
Modifier and Type | Method and Description |
---|---|
List<String> |
command()
Returns this process builder's current program and arguments.
|
ProcessBuilder |
command(List<String> command)
Changes the program and arguments of this process builder.
|
ProcessBuilder |
command(String... command)
Changes the program and arguments of this process builder.
|
File |
directory()
Returns the working directory of this process builder.
|
ProcessBuilder |
directory(File directory)
Changes the working directory of this process builder.
|
Map<String,String> |
environment()
Returns this process builder's current environment.
|
boolean |
redirectErrorStream()
Indicates whether the standard error should be redirected to standard
output.
|
ProcessBuilder |
redirectErrorStream(boolean redirectErrorStream)
Changes the state of whether or not standard error is redirected to
standard output.
|
Process |
start()
Starts a new process based on the current state of this process builder.
|
public ProcessBuilder(String... command)
ProcessBuilder
instance with the specified
operating system program and its arguments.command
- the requested operating system program and its arguments.public ProcessBuilder(List<String> command)
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.command
- the requested operating system program and its arguments.NullPointerException
- if command
is null
.public List<String> command()
public ProcessBuilder command(String... command)
command
- the new operating system program and its arguments.public ProcessBuilder command(List<String> command)
command
- the new operating system program and its arguments.NullPointerException
- if command
is null
.public File directory()
null
is
returned, then the working directory of the Java process is used when a
process is started.null
.public ProcessBuilder directory(File directory)
null
, then the working directory of the Java
process is used when a process is started.directory
- the new working directory for this process builder.public Map<String,String> environment()
System.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.public boolean redirectErrorStream()
Process.getErrorStream()
will always
return end of stream and standard error is written to
Process.getInputStream()
.true
if the standard error is redirected; false
otherwise.public ProcessBuilder redirectErrorStream(boolean redirectErrorStream)
redirectErrorStream
- true
to redirect standard error, false
otherwise.public Process start() throws IOException
Process
instance.NullPointerException
- if any of the elements of command()
is null
.IndexOutOfBoundsException
- if command()
is empty.IOException
- if an I/O error happens.