public interface ProcessHandler
| Modifier and Type | Interface and Description |
|---|---|
static class |
ProcessHandler.ProcessCommand
Subprocess attributes passed to
start method. |
static class |
ProcessHandler.Redirect
Represents a source of subprocess input or a destination of subprocess output.
|
| Modifier and Type | Method and Description |
|---|---|
Process |
start(ProcessHandler.ProcessCommand command)
A request to start a new subprocess with given attributes.
|
Process start(ProcessHandler.ProcessCommand command) throws IOException
The default implementation uses ProcessBuilder to create the new subprocess. The
subprocess current working directory is set to ProcessHandler.ProcessCommand.getDirectory(). The
ProcessHandler.ProcessCommand.getDirectory() value was either explicitely set by the guest language
or the FileSystem's current working directory is used. The subprocess environment is
set to ProcessHandler.ProcessCommand.getEnvironment(), the initial value of
ProcessBuilder.environment() is cleaned. The ProcessHandler.ProcessCommand.getEnvironment()
contains the environment variables set by guest language and possibly also the JVM process
environment depending on value of
Context.Builder.allowEnvironmentAccess(org.graalvm.polyglot.EnvironmentAccess).
Implementation example:
publicProcessstart(ProcessCommand command) throwsIOException{ProcessBuilderbuilder = newProcessBuilder(command.getCommand()) .redirectErrorStream(command.isRedirectErrorStream()) .redirectInput(asProcessBuilderRedirect(command.getInputRedirect())) .redirectOutput(asProcessBuilderRedirect(command.getOutputRedirect())) .redirectError(asProcessBuilderRedirect(command.getErrorRedirect()));Map<String,String> env = builder.environment(); env.clear(); env.putAll(command.getEnvironment());Stringcwd = command.getDirectory(); if (cwd != null) { builder.directory(Paths.get(cwd).toFile()); } return builder.start(); }
command - the subprocess attributesSecurityException - if the process creation was forbidden by this handlerIOException - if the process fails to execute