Package htsjdk.samtools.util
Class ProcessExecutor
- java.lang.Object
-
- htsjdk.samtools.util.ProcessExecutor
-
public class ProcessExecutor extends Object
Utility class that will execute sub processes via Runtime.getRuntime().exec(...) and read off the output from stderr and stdout of the sub process. This implementation uses a different thread to read each stream: the current thread for stdout and another, internal thread for stderr. This utility is able to handle concurrent executions, spawning as many threads as are required to handle the concurrent load.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ProcessExecutor.ExitStatusAndOutput
-
Constructor Summary
Constructors Constructor Description ProcessExecutor()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
execute(String command)
Executes the command via Runtime.getRuntime().exec() then writes stderr to log.error and stdout to log.info and blocks until the command is complete.static int
execute(String[] commandParts)
Executes the command via Runtime.getRuntime().exec() then writes stderr to log.error and stdout to log.info and blocks until the command is complete.static int
execute(String[] commandParts, String outputStreamString)
Executes the command via Runtime.getRuntime().exec(), writesoutputStreamString
to the process output stream if it is not null, then writes stderr to log.error and stdout to log.info and blocks until the command is complete.static ProcessExecutor.ExitStatusAndOutput
executeAndReturnInterleavedOutput(String command)
Execute the command and capture stdout and stderr.static ProcessExecutor.ExitStatusAndOutput
executeAndReturnInterleavedOutput(String[] commandArray)
Execute the command and capture stdout and stderr.static String
executeAndReturnResult(String command)
-
-
-
Method Detail
-
execute
public static int execute(String command)
Executes the command via Runtime.getRuntime().exec() then writes stderr to log.error and stdout to log.info and blocks until the command is complete.- Parameters:
command
- command string- Returns:
- return code of command
- See Also:
Runtime.exec(String)
-
execute
public static int execute(String[] commandParts)
Executes the command via Runtime.getRuntime().exec() then writes stderr to log.error and stdout to log.info and blocks until the command is complete.- Parameters:
commandParts
- command string- Returns:
- return code of command
- See Also:
Runtime.exec(String[])
-
execute
public static int execute(String[] commandParts, String outputStreamString)
Executes the command via Runtime.getRuntime().exec(), writesoutputStreamString
to the process output stream if it is not null, then writes stderr to log.error and stdout to log.info and blocks until the command is complete.- Parameters:
commandParts
- command string- Returns:
- return code of command
- See Also:
Runtime.exec(String[])
-
executeAndReturnInterleavedOutput
public static ProcessExecutor.ExitStatusAndOutput executeAndReturnInterleavedOutput(String command)
Execute the command and capture stdout and stderr.- Returns:
- Exit status of command, and both stderr and stdout interleaved into stdout attribute.
-
executeAndReturnInterleavedOutput
public static ProcessExecutor.ExitStatusAndOutput executeAndReturnInterleavedOutput(String[] commandArray)
Execute the command and capture stdout and stderr.- Returns:
- Exit status of command, and both stderr and stdout interleaved into stdout attribute.
-
-