Package it.tidalwave.util
Interface ProcessExecutor
-
public interface ProcessExecutor
A 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 interface
ProcessExecutor.ConsoleOutput
A container of the console output of the process.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static ProcessExecutor
forExecutable(java.lang.String executable)
Specifies the executable to run.ProcessExecutor.ConsoleOutput
getStderr()
ProcessExecutor.ConsoleOutput
getStdout()
ProcessExecutor
send(java.lang.String string)
Sends some input to the external process.ProcessExecutor
start()
Launches the external process and starts collecting its output (which can be analyzed by callinggetStdout()
andgetStderr()
.ProcessExecutor
waitForCompletion()
Waits for the completion of the external process.ProcessExecutor
withArgument(java.lang.String argument)
Specifies a single argument for the executable.ProcessExecutor
withArguments(java.lang.String... arguments)
Specifies some arguments for the executable.ProcessExecutor
withWorkingDirectory(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, anIOException
is 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()
-
-