Class DefaultProcessExecutor

java.lang.Object
it.tidalwave.util.spi.DefaultProcessExecutor
All Implemented Interfaces:
ProcessExecutor

@ThreadSafe public class DefaultProcessExecutor extends Object implements ProcessExecutor
Since:
1.39
Author:
Fabrizio Giudici
  • Constructor Details

    • DefaultProcessExecutor

      public DefaultProcessExecutor()
  • Method Details

    • forExecutable

      @Nonnull public static DefaultProcessExecutor forExecutable(@Nonnull String executable)
      Factory method for associating an executable. It returns an intermediate executor that must be configured and later started. Under Windows, the '.exe' suffix is automatically appended to the name of the executable.
      Parameters:
      executable - the executable (with the full path)
      Returns:
      the executor
      See Also:
    • withArgument

      @Nonnull public DefaultProcessExecutor withArgument(@Nonnull String argument)
      Adds a single argument to pass to the external process.
      Specified by:
      withArgument in interface ProcessExecutor
      Parameters:
      argument - the argument
      Returns:
      itself for chaining methods
    • withArguments

      @Nonnull public DefaultProcessExecutor withArguments(@Nonnull String... arguments)
      Adds some arguments to pass to the external process.
      Specified by:
      withArguments in interface ProcessExecutor
      Parameters:
      arguments - the arguments
      Returns:
      itself for chaining methods
    • start

      @Nonnull public DefaultProcessExecutor start() throws IOException
      Starts the external process.
      Specified by:
      start in interface ProcessExecutor
      Returns:
      itself for chaining methods
      Throws:
      IOException - in case of error
    • stop

      public void stop()
      Stops the external process.
      Specified by:
      stop in interface ProcessExecutor
    • waitForCompletion

      @Nonnull public DefaultProcessExecutor waitForCompletion() throws InterruptedException
      Waits for the termination of the external process.
      Specified by:
      waitForCompletion in interface ProcessExecutor
      Returns:
      itself for chaining methods
      Throws:
      InterruptedException - if the wait has been interrupted
    • send

      @Nonnull public DefaultProcessExecutor send(@Nonnull String string)
      Sends a string to the stdin of the running process. If a carriage return is needed, it must be explicitly placed in the string.
      Specified by:
      send in interface ProcessExecutor
      Parameters:
      string - the string to send
      Returns:
      itself for chaining methods