Class Executor

java.lang.Object
org.robovm.compiler.util.Executor
All Implemented Interfaces:
Launcher

public class Executor
extends Object
implements Launcher
Builder style wrapper around commons-exec which also adds support for asynchronous execution.
  • Constructor Details

    • Executor

      public Executor​(Logger logger, String cmd)
      Creates a new instance which will execute the specified command.
      Parameters:
      logger - Logger used by this Executor.
      cmd - the command to be executed. Either the full path to an executable or the name of an executable which will be searched for in the search paths specified by the PATH environment variable.
    • Executor

      public Executor​(Logger logger, File cmd)
      Creates a new instance which will execute the specified command.
      Parameters:
      logger - Logger used by this Executor.
      cmd - the command to be executed.
  • Method Details

    • args

      public Executor args​(Collection<Object> args)
      Adds arguments from the specified Collection. File arguments will be converted to absolute paths using File.getAbsolutePath(). All other types of args will be converted to Strings using Object.toString().
      Parameters:
      args - the arguments to add.
      Returns:
      this Executor.
    • args

      public Executor args​(Object... args)
      Adds one or more argument. File arguments will be converted to absolute paths using File.getAbsolutePath(). All other types of args will be converted to Strings using Object.toString().
      Parameters:
      args - the argument(s) to add.
      Returns:
      this Executor.
    • env

      public Executor env​(Map<String,​String> env)
      Sets the environment variables for the child process.
      Parameters:
      env - the environment variables.
      Returns:
      this Executor.
    • addEnv

      public Executor addEnv​(String name, String value)
      Adds a single environment variable.
      Parameters:
      env - the environment variables.
      Returns:
      this Executor.
    • inheritEnv

      public Executor inheritEnv​(boolean b)
      Sets whether the parent's environment variables should be inherited by the child process. Defaults to true.
      Parameters:
      b - true or false.
      Returns:
      this Executor.
    • wd

      public Executor wd​(File wd)
      Sets the working directory of the child process. If not set the working directory will be the same as the parent's.
      Parameters:
      wd - the working directory.
      Returns:
      this Executor.
    • errOut

      public Executor errOut​(OutputStream out)
      Redirects the stdout and stderr streams of the child process to the specified OutputStream. If not specified stdout and stderr will be inherited from the parent process.
      Parameters:
      out - the OutputStream.
      Returns:
      this Executor.
    • out

      public Executor out​(OutputStream out)
      Redirects the stdout stream of the child process to the specified OutputStream. If not specified stdout will be inherited from the parent process.
      Parameters:
      out - the OutputStream.
      Returns:
      this Executor.
    • err

      public Executor err​(OutputStream err)
      Redirects the stderr stream of the child process to the specified OutputStream. If not specified stderr will be inherited from the parent process.
      Parameters:
      err - the OutputStream.
      Returns:
      this Executor.
    • in

      public Executor in​(InputStream in)
      Uses the specified InputStream as the stdin stream for the child process.
      Parameters:
      in - the InputStream.
      Returns:
      this Executor.
    • streamHandler

      public Executor streamHandler​(org.apache.commons.exec.ExecuteStreamHandler streamHandler)
      Sets the ExecuteStreamHandler to be used by the underlying Executor. If set any streams set by out(OutputStream), err(OutputStream), errOut(OutputStream) or in(InputStream) will be ignored.
      Parameters:
      streamHandler - the ExecuteStreamHandler to be used.
      Returns:
      this Executor.
    • closeOutputStreams

      public Executor closeOutputStreams​(boolean b)
      Sets whether the stdout and stderr OutputStreams should be closed after the command has finished.
      Parameters:
      b - true or false.
    • exec

      public int exec() throws org.apache.commons.exec.ExecuteException, IOException
      Throws:
      org.apache.commons.exec.ExecuteException
      IOException
    • execAsync

      public Process execAsync() throws IOException
      Specified by:
      execAsync in interface Launcher
      Throws:
      IOException
    • execCapture

      public String execCapture() throws IOException
      Throws:
      IOException