Package nl.vpro.util
Class CommandExecutorImpl
- java.lang.Object
-
- nl.vpro.util.CommandExecutorImpl
-
- All Implemented Interfaces:
CommandExecutor
public class CommandExecutorImpl extends Object implements 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 Modifier and Type Class Description static class
CommandExecutorImpl.Builder
-
Nested classes/interfaces inherited from interface nl.vpro.util.CommandExecutor
CommandExecutor.BrokenPipe, CommandExecutor.ExitCodeException, CommandExecutor.Parameters
-
-
Constructor Summary
Constructors Constructor Description CommandExecutorImpl(File f)
CommandExecutorImpl(File f, File workdir)
CommandExecutorImpl(String c)
CommandExecutorImpl(String binary, File workdir)
CommandExecutorImpl(String binary, File workdir, Duration processTimeout)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CommandExecutorImpl.Builder
builder()
protected static String
commandToString(List<String> command)
protected static String
escapeForBash(String m)
int
execute(String... args)
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 streamSupplier<String>
getBinary()
static Optional<File>
getExecutable(String... proposals)
static Optional<File>
getExecutable(Collection<File> proposals)
static Optional<File>
getExecutableFromStrings(Collection<String> proposals)
SimpleLogger
getLogger()
String
toString()
-
-
-
Method Detail
-
getExecutable
public static Optional<File> getExecutable(Collection<File> proposals)
-
getExecutableFromStrings
public static Optional<File> getExecutableFromStrings(Collection<String> proposals)
-
execute
public int execute(String... args)
Executes the command with given arguments. Output is logged only.- Specified by:
execute
in interfaceCommandExecutor
- Returns:
- The exit code
-
execute
public 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 stream- Specified by:
execute
in interfaceCommandExecutor
- Parameters:
parameters
- The parameters for doing this wrapped in aCommandExecutor.Parameters
object.- Returns:
- The exit code
-
getLogger
public SimpleLogger getLogger()
- Specified by:
getLogger
in interfaceCommandExecutor
-
builder
public static CommandExecutorImpl.Builder builder()
-
-