Class ProcessUtils
java.lang.Object
fr.ens.biologie.genomique.eoulsan.util.ProcessUtils
Utility class for launching external process.
- Since:
- 1.0
- Author:
- Laurent Jourdren
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThis class allow to fetch standard error of the process, without printing -
Method Summary
Modifier and TypeMethodDescriptionstatic voidExecute a command with the OS.static voidexecThreadOutput(String cmd) Execute a command and write the content of the standard output and error to System.out and System.err.static voidexecThreadOutput(String[] cmd) Execute a command and write the content of the standard output and error to System.out and System.err.static StringexecToString(String cmd) Execute a command with the OS and return the output in a string.static StringexecToString(String cmd, boolean addStdErr, boolean checkExitCode) Execute a command with the OS and return the output in a string.static voidexecWriteOutput(String cmd, File outputFile) Execute a command with the OS and save the output in file.getExecutablePids(String executableName) Return a set withs pid of existing executable.static voidlogEndTime(Process p, String cmd, long startTime) Log the time of execution of a process.static intExecute a command.static intExecute a command.static intExecute a command.static voidthrowExitCodeException(int exitCode, String command) Throw an IOException if the exit code of a process is not equals to 0.static voidwaitRandom(int maxMilliseconds) Wait a random number of milliseconds.static voidwaitUntilExecutableRunning(String executableName) Wait the end of the execution of all the instance of an executable.
-
Method Details
-
system
Execute a command.- Parameters:
cmd- command to execute- Returns:
- the exit error of the program
- Throws:
IOException- if an error occurs while executing the command
-
sh
Execute a command.- Parameters:
cmd- command to execute- Returns:
- the exit error of the program
- Throws:
IOException- if an error occurs while executing the command
-
sh
Execute a command.- Parameters:
cmd- command to executetemporaryDirectory- temporary where create the temporary shell file- Returns:
- the exit error of the program
- Throws:
IOException- if an error occurs while executing the command
-
exec
Execute a command with the OS.- Parameters:
cmd- Command to executestdOutput- don't show the result of the command on the standard output- Throws:
IOException- if an error occurs while running the process
-
execWriteOutput
Execute a command with the OS and save the output in file.- Parameters:
cmd- Command to executeoutputFile- The output file- Throws:
IOException- if an error occurs while running the process
-
execToString
Execute a command with the OS and return the output in a string.- Parameters:
cmd- Command to execute- Returns:
- a string with the output the command
- Throws:
IOException- if an error occurs while running the process
-
execToString
public static String execToString(String cmd, boolean addStdErr, boolean checkExitCode) throws IOException Execute a command with the OS and return the output in a string.- Parameters:
cmd- Command to executeaddStdErr- add the output of stderr in the resultcheckExitCode- if true exit code will be checked- Returns:
- a string with the output the command
- Throws:
IOException- if an error occurs while running the process
-
logEndTime
Log the time of execution of a process.- Parameters:
p- Process to logcmd- Command of the processstartTime- Start time in ms- Throws:
IOException- if an error occurs at the end of the process
-
throwExitCodeException
Throw an IOException if the exit code of a process is not equals to 0.- Parameters:
exitCode- the exit codecommand- the executed command- Throws:
IOException- if the exit code if not 0
-
getExecutablePids
Return a set withs pid of existing executable.- Parameters:
executableName- executable name- Returns:
- a set of integers with pid of existing executable
-
waitUntilExecutableRunning
Wait the end of the execution of all the instance of an executable.- Parameters:
executableName- name of the executable
-
waitRandom
public static void waitRandom(int maxMilliseconds) Wait a random number of milliseconds.- Parameters:
maxMilliseconds- the maximum number of milliseconds to wait
-
execThreadOutput
Execute a command and write the content of the standard output and error to System.out and System.err.- Parameters:
cmd- Command to execute- Throws:
IOException- if an error occurs while executing the command
-
execThreadOutput
Execute a command and write the content of the standard output and error to System.out and System.err.- Parameters:
cmd- array with the command to execute- Throws:
IOException- if an error occurs while executing the command
-