Package it.tidalwave.util
Interface ProcessExecutor
-
- All Known Implementing Classes:
DefaultProcessExecutor
@ThreadSafe public interface ProcessExecutor
A facility that provides means for launching an external process, scraping its stdout and stderr in real-time and sending commands by means of its stdin.- Since:
- 1.39
- Author:
- Fabrizio Giudici
- See Also:
DefaultProcessExecutor
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ProcessExecutor.ConsoleOutput
This interface provides operations that can be performed on the stdout or stderr consoles attached to the external process.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ProcessExecutor.ConsoleOutput
getStderr()
Returns the stderr console.ProcessExecutor.ConsoleOutput
getStdout()
Returns the stdout console.ProcessExecutor
send(java.lang.String string)
Sends a string to the stdin of the running process.ProcessExecutor
start()
Starts the external process.void
stop()
Stops the external process.ProcessExecutor
waitForCompletion()
Waits for the termination of the external process.ProcessExecutor
withArgument(java.lang.String argument)
Adds a single argument to pass to the external process.ProcessExecutor
withArguments(java.lang.String... arguments)
Adds some arguments to pass to the external process.
-
-
-
Method Detail
-
withArguments
@Nonnull ProcessExecutor withArguments(@Nonnull java.lang.String... arguments)
Adds some arguments to pass to the external process.- Parameters:
arguments
- the arguments- Returns:
- itself for chaining methods
-
withArgument
@Nonnull ProcessExecutor withArgument(@Nonnull java.lang.String argument)
Adds a single argument to pass to the external process.- Parameters:
argument
- the argument- Returns:
- itself for chaining methods
-
start
@Nonnull ProcessExecutor start() throws java.io.IOException
Starts the external process.- Returns:
- itself for chaining methods
- Throws:
java.io.IOException
- in case of error
-
stop
void stop()
Stops the external process.
-
waitForCompletion
@Nonnull ProcessExecutor waitForCompletion() throws java.io.IOException, java.lang.InterruptedException
Waits for the termination of the external process.- Returns:
- itself for chaining methods
- Throws:
java.lang.InterruptedException
- if the wait has been interruptedjava.io.IOException
- in case of I/O error
-
send
@Nonnull ProcessExecutor send(@Nonnull java.lang.String string) throws java.io.IOException
Sends a string to the stdin of the running process. If a carriage return is needed, it must be explicitly placed in the string.- Parameters:
string
- the string to send- Returns:
- itself for chaining methods
- Throws:
java.io.IOException
- in case of I/O error
-
getStdout
@Nonnull ProcessExecutor.ConsoleOutput getStdout()
Returns the stdout console.- Returns:
- the console
-
getStderr
@Nonnull ProcessExecutor.ConsoleOutput getStderr()
Returns the stderr console.- Returns:
- the console
-
-