public final class ProcessBuilder extends Object implements Callable<Process>, Lookup.Provider
ProcessBuilder.call()
method. You can
also (re)configure the builder and spawn a different process.
Note the API does not prescribe the actual meaning of Process
.
It may be local process, remote process or some other implementation.
You can use the default implementation returned by ProcessBuilder.getLocal()
for creating the local machine OS processes.
Thread safety of this class depends on thread safety of the implementation class.
If the ProcessBuilderImplementation
is used and it is thread
safe (if possible the implementation should be even stateless) this class
is thread safe as well.
If the ProcessBuilderImplementation
is used and it is (including
EnvironmentImplementation
) thread safe and does not have any mutable
configuration accessible via ProcessBuilderImplementation.getLookup()
it is thread safe as well. Otherwise it is not thread safe.
The synchronization mechanism used in this object is the ProcessBuilderImplementation
object monitor.
Modifier and Type | Method and Description |
---|---|
Process |
call()
Creates the new
Process based on the properties configured
in this builder. |
String |
getDescription()
Returns the human readable description of this builder.
|
Environment |
getEnvironment()
Returns the object for environment variables manipulation.
|
static ProcessBuilder |
getLocal()
Returns the
ProcessBuilder creating the OS process on local
machine. |
Lookup |
getLookup()
Returns the associated
Lookup . |
void |
setArguments(List<String> arguments)
Sets the arguments passed to the process created by subsequent call
of
ProcessBuilder.call() . |
void |
setExecutable(String executable)
Sets the executable to run.
|
void |
setRedirectErrorStream(boolean redirectErrorStream)
Configures the error stream redirection.
|
void |
setWorkingDirectory(String workingDirectory)
Sets the working directory for the process created by subsequent call
of
ProcessBuilder.call() . |
public static ProcessBuilder getLocal()
ProcessBuilder
creating the OS process on local
machine. Returned implementation is thread safe
.
The returned builder also attempts to properly configure HTTP proxy
for the process.ProcessBuilder
creating the OS process on local
machine@NonNull public String getDescription()
public void setExecutable(@NonNull String executable)
ProcessBuilder.call()
methods throws IllegalStateException
when there is no executable
configured.executable
- the executable to runpublic void setWorkingDirectory(@NullAllowed String workingDirectory)
ProcessBuilder.call()
. The default value is implementation specific.workingDirectory
- the working directory of the processpublic void setArguments(@NonNull List<String> arguments)
ProcessBuilder.call()
. By default there are no arguments.arguments
- the arguments passed to the processpublic void setRedirectErrorStream(boolean redirectErrorStream)
true
the error
stream of process created by subsequent call of ProcessBuilder.call()
method
will be redirected to standard output stream.redirectErrorStream
- the error stream redirection@NonNull public Environment getEnvironment()
public Lookup getLookup()
Lookup
. Extension point provided by
ProcessBuilderImplementation
.getLookup
in interface Lookup.Provider
Lookup
.ProcessBuilderImplementation.getLookup()
@NonNull public Process call() throws IOException
Process
based on the properties configured
in this builder.
Actual behavior depends on the builder implementation, but it should respect all the properties configured on this builder.
call
in interface Callable<Process>
Process
based on the properties configured
in this builderIOException
- if the process could not be createdIllegalStateException
- if there is no executable configured
by ProcessBuilder.setExecutable(java.lang.String)
ProcessBuilderImplementation