Java exec execute(String[] _command, String _workingDir)

Here you can find the source of execute(String[] _command, String _workingDir)

Description

execute

License

Apache License

Declaration

public static boolean execute(String[] _command, String _workingDir) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;

public class Main {

    public static boolean execute(String[] _command, String _workingDir) {
        try {/*from   w w  w.  ja  va  2 s .  co m*/
            Process p = Runtime.getRuntime().exec(_command, null, new File(_workingDir));

            BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

            String line = "";
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
            int exitVal = p.waitFor();
            //System.out.println("exec result : "+exitVal);
            reader.close();

        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}

Related

  1. execute(String command, Process p, String[] output, boolean cmdStatus)
  2. execute(String url)
  3. execute(String... cmdarray)
  4. execute(String... command)
  5. execute(String... commands)
  6. execute(String[] command, File directory, String[] env)
  7. execute(String[] commandArray)
  8. execute(Template template, Map rootMap)
  9. execute1(final String appPath)