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.
|
org.graalvm.polyglot.io.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(org.graalvm.polyglot.io.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(org.graalvm.polyglot.io.ProcessHandler.Redirect source)
Sets the standard input source.
|
TruffleProcessBuilder |
redirectOutput(org.graalvm.polyglot.io.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 argumentsbuilderpublic TruffleProcessBuilder command(String... command)
command - the string array containing the executable and its argumentsbuilderpublic 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 directorybuilderpublic TruffleProcessBuilder redirectErrorStream(boolean enabled)
true the standard error output is merged into standard output.enabled - enables merging of standard error output into standard outputbuilderpublic TruffleProcessBuilder redirectInput(org.graalvm.polyglot.io.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 sourcebuilderpublic TruffleProcessBuilder redirectOutput(org.graalvm.polyglot.io.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 destinationbuilderpublic TruffleProcessBuilder redirectError(org.graalvm.polyglot.io.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 destinationbuilderpublic 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 inheritancebuilderpublic TruffleProcessBuilder clearEnvironment(boolean clear)
true the environment variables are not inherited by the subprocess.clear - disables inheritance of environment variablesbuilderpublic TruffleProcessBuilder environment(String name, String value)
name - the variable namevalue - the valuebuilderpublic TruffleProcessBuilder environment(Map<String,String> environment)
environment variables
using a map. All values of the provided map must be non-null.environment - environment variablesbuilderTo set a single environment variable.public org.graalvm.polyglot.io.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 nullpublic 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 ProcessHandlerIOException - if the process fails to execute