Class DefaultProcessExecutor

  • All Implemented Interfaces:
    ProcessExecutor

    @ThreadSafe
    public class DefaultProcessExecutor
    extends java.lang.Object
    implements ProcessExecutor
    Since:
    1.39
    Author:
    Fabrizio Giudici
    • Constructor Detail

      • DefaultProcessExecutor

        public DefaultProcessExecutor()
    • Method Detail

      • forExecutable

        @Nonnull
        public static DefaultProcessExecutor forExecutable​(@Nonnull
                                                           java.lang.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:
        start()
      • withArgument

        @Nonnull
        public DefaultProcessExecutor withArgument​(@Nonnull
                                                   java.lang.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
                                                    java.lang.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 java.io.IOException
        Starts the external process.
        Specified by:
        start in interface ProcessExecutor
        Returns:
        itself for chaining methods
        Throws:
        java.io.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 java.lang.InterruptedException
        Waits for the termination of the external process.
        Specified by:
        waitForCompletion in interface ProcessExecutor
        Returns:
        itself for chaining methods
        Throws:
        java.lang.InterruptedException - if the wait has been interrupted
      • send

        @Nonnull
        public DefaultProcessExecutor send​(@Nonnull
                                           java.lang.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