ProcessBuilder
@Deprecated public final class ProcessBuilder extends Object implements Callable<Process>
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 ProcessBuilderImplementation
the class is using. If it is thread
safe (if possible the implementation should be even stateless) this class
is thread safe as well.
Modifier and Type | Method and Description |
---|---|
Process |
call()
Deprecated.
Creates the new
Process based on the properties configured
in this builder. |
String |
getDescription()
Deprecated.
Returns the human readable description of this builder.
|
static ProcessBuilder |
getLocal()
Deprecated.
Returns the
ProcessBuilder creating the OS process on local
machine. |
void |
setArguments(List<String> arguments)
Deprecated.
Sets the arguments passed to the process created by subsequent call
of
ProcessBuilder.call() . |
void |
setEnvironmentVariables(Map<String,String> envVariables)
Deprecated.
Sets the environment variables for the process created by subsequent call
of
ProcessBuilder.call() . |
void |
setExecutable(String executable)
Deprecated.
Sets the executable to run.
|
void |
setPaths(List<String> paths)
Deprecated.
Sets the additional paths to be included in
PATH environment
variable for the process. |
void |
setRedirectErrorStream(boolean redirectErrorStream)
Deprecated.
Configures the error stream redirection.
|
void |
setWorkingDirectory(String workingDirectory)
Deprecated.
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
.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 setEnvironmentVariables(@NonNull Map<String,String> envVariables)
ProcessBuilder.call()
. By default there are no environment variables with
exception of PATH
possibly configured by ProcessBuilder.setPaths(java.util.List)
.envVariables
- the environment variables for the processpublic void setPaths(@NonNull List<String> paths)
PATH
environment
variable for the process.paths
- the additional paths to be included in PATH
environment variablepublic 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 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.
Since version 1.35 implementors of this method are advised to throw
a UserQuestionException
in case the execution cannot be
performed and requires additional user confirmation, or configuration.
Callers of this method may check for this exception and handle it
appropriately.
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)
UserQuestionException
- if the execution cannot be performed
without permission from the userProcessBuilderImplementation