Package it.tidalwave.util.spi
Class DefaultProcessExecutor
- java.lang.Object
-
- it.tidalwave.util.spi.DefaultProcessExecutor
-
- All Implemented Interfaces:
ProcessExecutor
@ThreadSafe public class DefaultProcessExecutor extends java.lang.Object implements ProcessExecutor
- Since:
- 1.39
- Author:
- Fabrizio Giudici
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
DefaultProcessExecutor.DefaultConsoleOutput
-
Nested classes/interfaces inherited from interface it.tidalwave.util.ProcessExecutor
ProcessExecutor.ConsoleOutput
-
-
Constructor Summary
Constructors Constructor Description DefaultProcessExecutor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DefaultProcessExecutor
forExecutable(java.lang.String executable)
Factory method for associating an executable.DefaultProcessExecutor
send(java.lang.String string)
Sends a string to the stdin of the running process.DefaultProcessExecutor
start()
Starts the external process.void
stop()
Stops the external process.DefaultProcessExecutor
waitForCompletion()
Waits for the termination of the external process.DefaultProcessExecutor
withArgument(java.lang.String argument)
Adds a single argument to pass to the external process.DefaultProcessExecutor
withArguments(java.lang.String... arguments)
Adds some arguments to pass to the external process.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface it.tidalwave.util.ProcessExecutor
getStderr, getStdout
-
-
-
-
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 interfaceProcessExecutor
- 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 interfaceProcessExecutor
- 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 interfaceProcessExecutor
- 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 interfaceProcessExecutor
-
waitForCompletion
@Nonnull public DefaultProcessExecutor waitForCompletion() throws java.io.IOException, java.lang.InterruptedException
Waits for the termination of the external process.- Specified by:
waitForCompletion
in interfaceProcessExecutor
- Returns:
- itself for chaining methods
- Throws:
java.io.IOException
- in case of I/O errorjava.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 interfaceProcessExecutor
- Parameters:
string
- the string to send- Returns:
- itself for chaining methods
-
-