Class TruffleProcessBuilder
TruffleProcessBuilder instance
allows to set subprocess attributes. The start() method creates a new Process
instance with those attributes. The start() method can be invoked repeatedly from the
same instance to create new subprocesses with the same attributes.- Since:
- 19.1.0
-
Method Summary
Modifier and TypeMethodDescriptionclearEnvironment(boolean clear) Iftruethe environment variables are not inherited by the subprocess.Sets the executable and arguments.Sets the executable and arguments.org.graalvm.polyglot.io.ProcessHandler.RedirectcreateRedirectToStream(OutputStream stream) Creates a redirect to write into the givenOutputStream.directory(TruffleFile currentWorkingDirectory) Sets this process current working directory.environment(String name, String value) Sets the subprocess environment variable.environment(Map<String, String> environment) Shortcut for setting multipleenvironment variablesusing a map.inheritIO(boolean enabled) Iftruethe subprocess standard input, output and error output are the same as those of the current Java process.redirectError(org.graalvm.polyglot.io.ProcessHandler.Redirect destination) Sets the standard error output destination.redirectErrorStream(boolean enabled) Iftruethe standard error output is merged into standard output.redirectInput(org.graalvm.polyglot.io.ProcessHandler.Redirect source) Sets the standard input source.redirectOutput(org.graalvm.polyglot.io.ProcessHandler.Redirect destination) Sets the standard output destination.start()Starts a new subprocess using the attributes of this builder.
-
Method Details
-
command
Sets the executable and arguments.- Parameters:
command- the list containing the executable and its arguments- Returns:
- this
builder - Since:
- 19.1.0
-
command
Sets the executable and arguments.- Parameters:
command- the string array containing the executable and its arguments- Returns:
- this
builder - Since:
- 19.1.0
-
directory
Sets this process current working directory. ThecurrentWorkingDirectorymay benull, in this case the subprocess current working directory is set tofile system current working directory.- Parameters:
currentWorkingDirectory- the new current working directory- Returns:
- this
builder - Since:
- 19.1.0
-
redirectErrorStream
Iftruethe standard error output is merged into standard output.- Parameters:
enabled- enables merging of standard error output into standard output- Returns:
- this
builder - Since:
- 19.1.0
-
redirectInput
Sets the standard input source. Process started by thestart()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 byProcess.getOutputStream(). If the source is set toINHERIT, then theProcess.getOutputStream()returns a closed output stream.- Parameters:
source- the new standard input source- Returns:
- this
builder - Since:
- 19.1.0
-
redirectOutput
public TruffleProcessBuilder redirectOutput(org.graalvm.polyglot.io.ProcessHandler.Redirect destination) Sets the standard output destination. Process started by thestart()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 byProcess.getInputStream(). If the destination is set to is set toINHERIT, thenProcess.getInputStream()returns a closed input stream.- Parameters:
destination- the new standard output destination- Returns:
- this
builder - Since:
- 19.1.0
-
redirectError
public TruffleProcessBuilder redirectError(org.graalvm.polyglot.io.ProcessHandler.Redirect destination) Sets the standard error output destination. Process started by thestart()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 byProcess.getErrorStream(). If the destination is set to is set toINHERIT, thenProcess.getErrorStream()returns a closed input stream.- Parameters:
destination- the new error output destination- Returns:
- this
builder - Since:
- 19.1.0
-
inheritIO
Iftruethe subprocess standard input, output and error output are the same as those of the current Java process.- Parameters:
enabled- enables standard I/O inheritance- Returns:
- this
builder - Since:
- 19.1.0
-
clearEnvironment
Iftruethe environment variables are not inherited by the subprocess.- Parameters:
clear- disables inheritance of environment variables- Returns:
- this
builder - Since:
- 19.1.0
-
environment
Sets the subprocess environment variable.- Parameters:
name- the variable namevalue- the value- Returns:
- this
builder - Since:
- 19.1.0
-
environment
Shortcut for setting multipleenvironment variablesusing a map. All values of the provided map must be non-null.- Parameters:
environment- environment variables- Returns:
- this
builder - Since:
- 19.1.0
- See Also:
-
createRedirectToStream
Creates a redirect to write into the givenOutputStream.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.
- Parameters:
stream- theOutputStreamto write into- Throws:
NullPointerException- if the given stream isnull- Since:
- 19.2.0
-
start
Starts a new subprocess using the attributes of this builder. The new process invokes the command with arguments given bycommand(java.lang.String...), in a working directory given bydirectory(com.oracle.truffle.api.TruffleFile), with a process environment inherited fromContextand possibly extended byenvironment(java.lang.String, java.lang.String).- Returns:
- a new
Processinstance - Throws:
NullPointerException- if an element of the command list is nullIndexOutOfBoundsException- if the command is an empty listSecurityException- when process creation is forbidden byProcessHandlerIOException- if the process fails to execute- Since:
- 19.1.0
-