Package it.tidalwave.util
Interface ProcessExecutor
-
public interface ProcessExecutorA helper class for launching an external process and handling its output.- Author:
- Fabrizio Giudici
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceProcessExecutor.ConsoleOutputA container of the console output of the process.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static ProcessExecutorforExecutable(java.lang.String executable)Specifies the executable to run.ProcessExecutor.ConsoleOutputgetStderr()ProcessExecutor.ConsoleOutputgetStdout()ProcessExecutorsend(java.lang.String string)Sends some input to the external process.ProcessExecutorstart()Launches the external process and starts collecting its output (which can be analyzed by callinggetStdout()andgetStderr().ProcessExecutorwaitForCompletion()Waits for the completion of the external process.ProcessExecutorwithArgument(java.lang.String argument)Specifies a single argument for the executable.ProcessExecutorwithArguments(java.lang.String... arguments)Specifies some arguments for the executable.ProcessExecutorwithWorkingDirectory(java.nio.file.Path workingDirectory)Specifies the working directory for the executable.
-
-
-
Method Detail
-
forExecutable
@Nonnull static ProcessExecutor forExecutable(@Nonnull java.lang.String executable) throws java.io.IOException
Specifies the executable to run. It is searched in the path.- Parameters:
executable- the executable- Returns:
- itself
- Throws:
java.io.IOException- if something goes wrong
-
withArgument
@Nonnull ProcessExecutor withArgument(@Nonnull java.lang.String argument)
Specifies a single argument for the executable. This method can be called multiple times.- Parameters:
argument- the argument- Returns:
- itself
-
withArguments
@Nonnull ProcessExecutor withArguments(@Nonnull java.lang.String... arguments)
Specifies some arguments for the executable. This method can be called multiple times.- Parameters:
arguments- the argument- Returns:
- itself
-
withWorkingDirectory
@Nonnull ProcessExecutor withWorkingDirectory(@Nonnull java.nio.file.Path workingDirectory)
Specifies the working directory for the executable.- Parameters:
workingDirectory- the working directory- Returns:
- itself
-
start
@Nonnull ProcessExecutor start() throws java.io.IOException
Launches the external process and starts collecting its output (which can be analyzed by callinggetStdout()andgetStderr().- Returns:
- itself
- Throws:
java.io.IOException- if something goes wrong
-
waitForCompletion
@Nonnull ProcessExecutor waitForCompletion() throws java.io.IOException, java.lang.InterruptedException
Waits for the completion of the external process. If the process terminates with a non-zero status code, anIOExceptionis thrown.- Returns:
- itself
- Throws:
ProcessExecutorException- if the process terminates with a non zero exit codejava.io.IOException- if something went wrongjava.lang.InterruptedException- if the process has been interrupted
-
send
@Nonnull ProcessExecutor send(@Nonnull java.lang.String string)
Sends some input to the external process.- Parameters:
string- the input to send- Returns:
- itself
-
getStdout
@Nonnull ProcessExecutor.ConsoleOutput getStdout()
-
getStderr
@Nonnull ProcessExecutor.ConsoleOutput getStderr()
-
-