Package pl.poznan.put.utility
Class ExecHelper
- java.lang.Object
-
- pl.poznan.put.utility.ExecHelper
-
- Direct Known Subclasses:
ImmutableExecHelper
@Immutable public abstract class ExecHelper extends Object
An executor of external processes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceExecHelper.ExecutionResultA result of running external command.
-
Constructor Summary
Constructors Constructor Description ExecHelper()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description List<String>arguments()abstract Stringcommand()static FilecreateRandomDirectory()Generates a random name and creates a directory named like that in system temporary directory.Map<String,String>environment()ExecHelper.ExecutionResultexecute()Executes the command in a working directory (if provided) with environment setting (if provided).abstract Optional<File>workingDirectory()
-
-
-
Method Detail
-
createRandomDirectory
public static File createRandomDirectory() throws IOException
Generates a random name and creates a directory named like that in system temporary directory.- Returns:
- A path to the created directory.
- Throws:
IOException- When it was impossible to create the random directory.
-
workingDirectory
public abstract Optional<File> workingDirectory()
- Returns:
- The working directory where to run the command in.
-
command
public abstract String command()
- Returns:
- The command to run.
-
execute
public ExecHelper.ExecutionResult execute() throws IOException
Executes the command in a working directory (if provided) with environment setting (if provided).- Returns:
- An object containing exit code with standard output and error streams.
- Throws:
IOException- When it was impossible to run the external command.
-
environment
@Default public Map<String,String> environment()
- Returns:
- The environment variables to be set during external command running (default: empty).
-
-