Java Utililty Methods exec

List of utility methods to do exec

Description

The list of methods to do exec are organized into topic(s).

Method

ProcessexecuteProcess(final File workDir, final String... termArray)
execute Process
final List<String> termList = Arrays.asList(termArray);
final ProcessBuilder builder = new ProcessBuilder(termList);
final Process process = builder.directory(workDir).start();
process.waitFor();
return process;
voidexecuteProcess(final String[] cmds)
execute Process
Thread processThread = new Thread(new Runnable() {
    @Override
    public void run() {
        try {
            Process childProcess = Runtime.getRuntime().exec(cmds);
            String line;
            BufferedReader outbr = new BufferedReader(new InputStreamReader(childProcess.getInputStream()));
            BufferedReader errbr = new BufferedReader(new InputStreamReader(childProcess.getErrorStream()));
...
StringexecuteProcess(String command)
execute Process
Process process = Runtime.getRuntime().exec(command);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
    stringBuilder.append(line).append("\n");
bufferedReader.close();
...
ListexecuteProcessAndGetOutputAsStringList(final String command)
Executes the given command Returns the output of the process as a List of strings
try {
    final Runtime runtime = Runtime.getRuntime();
    final Process process = runtime.exec(command);
    final InputStream inputStream = process.getInputStream();
    final InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
    final BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
    final List<String> stringList = new LinkedList<String>();
    while (true) {
...
voidexecutePUT(DataInputStream sockInp, DataOutputStream sockOutp)
execute PUT
try {
    String fileName = sockInp.readUTF();
    File putFile = new File(executePWD() + File.separator + getFileName(fileName));
    System.out.println(
            ":::: PUT file being copied file from client directory path :: " + putFile.getAbsolutePath());
    if (putFile.exists()) {
        sockOutp.writeUTF("File Already Exists");
    } else {
...
voidexecuteServer()
execute Server
String command = "cmd /C start" + System.getProperty("usr.dir") + "//src//test//java//config//run_test.bat";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);
voidexecuteShellCmdAndReturn(String cmd)
Execute a shell command and throw exception if command failed.
System.out.println(cmd);
Process process = Runtime.getRuntime().exec(cmd);
InputStream inputStream = process.getInputStream();
new BufferedReader(new InputStreamReader(inputStream));
booleanexecuteShellCommand(String command)
execute Shell Command
try {
    Process process = Runtime.getRuntime().exec(command);
    BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    int read;
    char[] buffer = new char[4096];
    StringBuffer output = new StringBuffer();
    while ((read = reader.read(buffer)) > 0) {
        output.append(buffer, 0, read);
...
ProcessexecuteShellCommand(String command)
execute Shell Command
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(command);
process.waitFor();
if (process.exitValue() != 0) {
    String error = convertStreamToString(process.getErrorStream());
    String output = convertStreamToString(process.getInputStream());
    throw new RuntimeException(output + "\n" + error); 
return process;
StringexecuteShellCommand(String command, File dir)
Run a shell command in the specified directory.
StringBuffer output = new StringBuffer();
System.out.println("Shell command:" + command);
Process p;
try {
    p = Runtime.getRuntime().exec(command, null, dir);
    p.waitFor();
    BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line = "";
...