Class ProcessUtils
- java.lang.Object
-
- fr.ens.biologie.genomique.eoulsan.util.ProcessUtils
-
public final class ProcessUtils extends Object
Utility class for launching external process.- Since:
- 1.0
- Author:
- Laurent Jourdren
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ProcessUtils.ProcessResult
static class
ProcessUtils.ProcessThreadErrOutput
This class allow to fetch standard error of the process, without printing
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
exec(String cmd, boolean stdOutput)
Execute a command with the OS.static void
execThreadOutput(String cmd)
Execute a command and write the content of the standard output and error to System.out and System.err.static void
execThreadOutput(String[] cmd)
Execute a command and write the content of the standard output and error to System.out and System.err.static String
execToString(String cmd)
Execute a command with the OS and return the output in a string.static String
execToString(String cmd, boolean addStdErr, boolean checkExitCode)
Execute a command with the OS and return the output in a string.static void
execWriteOutput(String cmd, File outputFile)
Execute a command with the OS and save the output in file.static Set<Integer>
getExecutablePids(String executableName)
Return a set withs pid of existing executable.static void
logEndTime(Process p, String cmd, long startTime)
Log the time of execution of a process.static int
sh(List<String> cmd)
Execute a command.static int
sh(List<String> cmd, File temporaryDirectory)
Execute a command.static int
system(String cmd)
Execute a command.static void
throwExitCodeException(int exitCode, String command)
Throw an IOException if the exit code of a process is not equals to 0.static void
waitRandom(int maxMilliseconds)
Wait a random number of milliseconds.static void
waitUntilExecutableRunning(String executableName)
Wait the end of the execution of all the instance of an executable.
-
-
-
Method Detail
-
system
public static int system(String cmd) throws IOException
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
public static int sh(List<String> cmd) throws IOException
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
public static int sh(List<String> cmd, File temporaryDirectory) throws IOException
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
public static void exec(String cmd, boolean stdOutput) throws IOException
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
public static void execWriteOutput(String cmd, File outputFile) throws IOException
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
public static String execToString(String cmd) throws IOException
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 result- Returns:
- a string with the output the command
- Throws:
IOException
- if an error occurs while running the process
-
logEndTime
public static void logEndTime(Process p, String cmd, long startTime) throws IOException
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
public static void throwExitCodeException(int exitCode, String command) throws IOException
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
public static Set<Integer> getExecutablePids(String executableName)
Return a set withs pid of existing executable.- Returns:
- a set of integers with pid of existing executable
-
waitUntilExecutableRunning
public static void waitUntilExecutableRunning(String executableName)
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
public static void execThreadOutput(String cmd) throws IOException
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
public static void execThreadOutput(String[] cmd) throws IOException
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
-
-