Package nl.vpro.util
Class CommandExecutorImpl
java.lang.Object
nl.vpro.util.CommandExecutorImpl
- All Implemented Interfaces:
CommandExecutor
Wrapper around ProcessorBuilder
It makes calling that somewhat simpler and also implements an interface, for easier mocking in test cases.
It supports a timeout, for implicit killing the process if it takes too long. It also can wrap stderr to log that as errors.
- Since:
- 1.6
- Author:
- Michiel Meeuwissen
-
Nested Class Summary
Nested classes/interfaces inherited from interface nl.vpro.util.CommandExecutor
CommandExecutor.BrokenPipe, CommandExecutor.ExitCodeException, CommandExecutor.Parameters
-
Constructor Summary
ConstructorDescriptionCommandExecutorImpl
(File f, File workdir) CommandExecutorImpl
(String binary, File workdir) CommandExecutorImpl
(String binary, File workdir, Duration processTimeout) -
Method Summary
Modifier and TypeMethodDescriptionstatic CommandExecutorImpl.Builder
builder()
protected static String
commandToString
(List<String> command) protected static String
int
Executes the command with given arguments.int
execute
(CommandExecutor.Parameters parameters) Executes the command with given arguments, catch the output and error streams in the given output streams, and provide standard input with the given input streamThe binary to wrapgetExecutable
(String... proposals) getExecutable
(Collection<File> proposals) getExecutableFromStrings
(Collection<String> proposals) nl.vpro.logging.simple.SimpleLogger
toString()
-
Constructor Details
-
CommandExecutorImpl
-
CommandExecutorImpl
-
CommandExecutorImpl
-
CommandExecutorImpl
-
CommandExecutorImpl
-
-
Method Details
-
getExecutable
-
getExecutable
-
getExecutableFromStrings
-
execute
Executes the command with given arguments. Output is logged only.- Specified by:
execute
in interfaceCommandExecutor
- Returns:
- The exit code
-
execute
Executes the command with given arguments, catch the output and error streams in the given output streams, and provide standard input with the given input stream- Specified by:
execute
in interfaceCommandExecutor
- Parameters:
parameters
- The parameters for doing this wrapped in aCommandExecutor.Parameters
object.- Returns:
- The exit code
-
commandToString
-
escapeForBash
-
getLogger
public nl.vpro.logging.simple.SimpleLogger getLogger()- Specified by:
getLogger
in interfaceCommandExecutor
-
toString
-
builder
-
getBinary
The binary to wrap- Specified by:
getBinary
in interfaceCommandExecutor
-