Methods Summary |
---|
public java.util.List | 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.
return command;
|
public java.lang.ProcessBuilder | command(java.lang.String command)Changes the program and arguments of this process builder.
return command(toList(command));
|
public java.lang.ProcessBuilder | command(java.util.List 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.
if (command == null) {
throw new NullPointerException();
}
this.command = command;
return this;
|
public java.io.File | directory()Returns the working directory of this process builder. If {@code null} is
returned, then the working directory of the Java process is used when a
process is started.
return directory;
|
public java.lang.ProcessBuilder | directory(java.io.File directory)Changes the working directory of this process builder. If the specified
directory is {@code null}, then the working directory of the Java
process is used when a process is started.
this.directory = directory;
return this;
|
public java.util.Map | 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 {@link 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.
return environment;
|
public java.lang.ProcessBuilder | redirectErrorStream(boolean redirectErrorStream)Changes the state of whether or not standard error is redirected to
standard output.
this.redirectErrorStream = redirectErrorStream;
return this;
|
public boolean | redirectErrorStream()Indicates whether the standard error should be redirected to standard
output. If redirected, the {@link Process#getErrorStream()} will always
return end of stream and standard error is written to
{@link Process#getInputStream()}.
return redirectErrorStream;
|
public java.lang.Process | start()Starts a new process based on the current state of this process builder.
if (command.isEmpty()) {
throw new IndexOutOfBoundsException();
}
String[] cmdArray = new String[command.size()];
for (int i = 0; i < cmdArray.length; i++) {
if ((cmdArray[i] = command.get(i)) == null) {
throw new NullPointerException();
}
}
String[] envArray = new String[environment.size()];
int i = 0;
for (Map.Entry<String, String> entry : environment.entrySet()) {
envArray[i++] = entry.getKey() + "=" + entry.getValue(); //$NON-NLS-1$
}
Process process = Runtime.getRuntime().exec(cmdArray, envArray,
directory);
// TODO implement support for redirectErrorStream
return process;
|
private static java.util.List | toList(java.lang.String[] strings)
ArrayList<String> arrayList = new ArrayList<String>(strings.length);
for (String string : strings) {
arrayList.add(string);
}
return arrayList;
|