public final class TruffleProcessBuilder extends Object
TruffleProcessBuilder
instance
allows to set subprocess attributes. The TruffleProcessBuilder.start()
method creates a new Process
instance with those attributes. The TruffleProcessBuilder.start()
method can be invoked repeatedly from the
same instance to create new subprocesses with the same attributes.Modifier and Type | Method and Description |
---|---|
TruffleProcessBuilder |
clearEnvironment(boolean clear)
If
true the environment variables are not inherited by the subprocess. |
TruffleProcessBuilder |
command(List<String> command)
Sets the executable and arguments.
|
TruffleProcessBuilder |
command(String... command)
Sets the executable and arguments.
|
ProcessHandler.Redirect |
createRedirectToStream(OutputStream stream)
Creates a redirect to write into the given
OutputStream . |
TruffleProcessBuilder |
directory(TruffleFile currentWorkingDirectory)
Sets this process current working directory.
|
TruffleProcessBuilder |
environment(Map<String,String> environment)
Shortcut for setting multiple
environment variables
using a map. |
TruffleProcessBuilder |
environment(String name,
String value)
Sets the subprocess environment variable.
|
TruffleProcessBuilder |
inheritIO(boolean enabled)
If
true the subprocess standard input, output and error output are the same as those
of the current Java process. |
TruffleProcessBuilder |
redirectError(ProcessHandler.Redirect destination)
Sets the standard error output destination.
|
TruffleProcessBuilder |
redirectErrorStream(boolean enabled)
If
true the standard error output is merged into standard output. |
TruffleProcessBuilder |
redirectInput(ProcessHandler.Redirect source)
Sets the standard input source.
|
TruffleProcessBuilder |
redirectOutput(ProcessHandler.Redirect destination)
Sets the standard output destination.
|
Process |
start()
Starts a new subprocess using the attributes of this builder.
|
public TruffleProcessBuilder command(List<String> command)
command
- the list containing the executable and its argumentsbuilder
public TruffleProcessBuilder command(String... command)
command
- the string array containing the executable and its argumentsbuilder
public TruffleProcessBuilder directory(TruffleFile currentWorkingDirectory)
currentWorkingDirectory
may be
null
, in this case the subprocess current working directory is set to
file system current working directory
.currentWorkingDirectory
- the new current working directorybuilder
public TruffleProcessBuilder redirectErrorStream(boolean enabled)
true
the standard error output is merged into standard output.enabled
- enables merging of standard error output into standard outputbuilder
public TruffleProcessBuilder redirectInput(ProcessHandler.Redirect source)
TruffleProcessBuilder.start()
method obtain its
standard input from this source.
If the source is PIPE
, the default value, then the standard input of a
subprocess can be written to using the output stream returned by
Process.getOutputStream()
. If the source is set to INHERIT
,
then the Process.getOutputStream()
returns a closed output stream.
source
- the new standard input sourcebuilder
public TruffleProcessBuilder redirectOutput(ProcessHandler.Redirect destination)
TruffleProcessBuilder.start()
method send its
standard output to this destination.
If the destination is PIPE
, the default value, then the standard output
of a subprocess can be read using the input stream returned by
Process.getInputStream()
. If the destination is set to is set to
INHERIT
, then Process.getInputStream()
returns a closed
input stream.
destination
- the new standard output destinationbuilder
public TruffleProcessBuilder redirectError(ProcessHandler.Redirect destination)
TruffleProcessBuilder.start()
method
send its error output to this destination.
If the destination is PIPE
, the default value, then the standard error
of a subprocess can be read using the input stream returned by
Process.getErrorStream()
. If the destination is set to is set to
INHERIT
, then Process.getErrorStream()
returns a closed
input stream.
destination
- the new error output destinationbuilder
public TruffleProcessBuilder inheritIO(boolean enabled)
true
the subprocess standard input, output and error output are the same as those
of the current Java process.enabled
- enables standard I/O inheritancebuilder
public TruffleProcessBuilder clearEnvironment(boolean clear)
true
the environment variables are not inherited by the subprocess.clear
- disables inheritance of environment variablesbuilder
public TruffleProcessBuilder environment(String name, String value)
name
- the variable namevalue
- the valuebuilder
public TruffleProcessBuilder environment(Map<String,String> environment)
environment variables
using a map. All values of the provided map must be non-null.environment
- environment variablesbuilder
To set a single environment variable.
public ProcessHandler.Redirect createRedirectToStream(OutputStream stream)
OutputStream
.
It is guaranteed that the process output (error output) is copied into the given stream
before the call to Process.waitFor()
method ends.
The stream is not closed when the process terminates.
stream
- the OutputStream
to write intoNullPointerException
- if the given stream is null
public Process start() throws IOException
TruffleProcessBuilder.command(java.lang.String...)
, in a working directory
given by TruffleProcessBuilder.directory(com.oracle.truffle.api.TruffleFile)
, with a process environment
inherited from Context
and possibly extended by
TruffleProcessBuilder.environment(java.lang.String, java.lang.String)
.Process
instanceNullPointerException
- if an element of the command list is nullIndexOutOfBoundsException
- if the command is an empty listSecurityException
- when process creation is forbidden by ProcessHandler
IOException
- if the process fails to execute