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
It may be local process, remote process or some other implementation.
You can use the default implementation returned by
for creating the local machine OS processes.
Thread safety of this class depends on thread safety of the implementation class.
ProcessBuilderImplementation is used and it is thread
safe (if possible the implementation should be even stateless) this class
is thread safe as well.
ProcessBuilderImplementation is used and it is (including
EnvironmentImplementation) thread safe and does not have any mutable
configuration accessible via
it is thread safe as well. Otherwise it is not thread safe.
The synchronization mechanism used in this object is the
|Modifier and Type||Method and Description|
Creates the new
Returns the human readable description of this builder.
Returns the object for environment variables manipulation.
Returns the associated
Sets the arguments passed to the process created by subsequent call of
Sets the executable to run.
Configures the error stream redirection.
Sets the working directory for the process created by subsequent call of
public static ProcessBuilder getLocal()
ProcessBuildercreating the OS process on local machine. Returned implementation is
thread safe. The returned builder also attempts to properly configure HTTP proxy for the process.
ProcessBuildercreating the OS process on local machine
@NonNull public String getDescription()
public void setExecutable(@NonNull String executable)
IllegalStateExceptionwhen there is no executable configured.
executable- the executable to run
public void setWorkingDirectory(@NullAllowed String workingDirectory)
ProcessBuilder.call(). The default value is implementation specific.
workingDirectory- the working directory of the process
public void setArguments(@NonNull List<String> arguments)
ProcessBuilder.call(). By default there are no arguments.
arguments- the arguments passed to the process
public void setRedirectErrorStream(boolean redirectErrorStream)
truethe 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
@NonNull public Process call() throws IOException
Processbased 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.
Processbased on the properties configured in this builder
IOException- if the process could not be created
IllegalStateException- if there is no executable configured by