Example usage for java.lang ProcessBuilder start

List of usage examples for java.lang ProcessBuilder start

Introduction

In this page you can find the example usage for java.lang ProcessBuilder start.

Prototype

public Process start() throws IOException 

Source Link

Document

Starts a new process using the attributes of this process builder.

Usage

From source file:com.atlassian.labs.bamboo.git.edu.nyu.cs.javagit.client.cli.ProcessUtilities.java

/**
 * Start a process.//from ww w.j  av a  2 s.  c  o m
 *
 * @param pb
 *          The <code>ProcessBuilder</code> to use to start the process.
 * @return The started process.
 * @exception IOException
 *              An <code>IOException</code> is thrown if there is trouble starting the
 *              sub-process.
 */
public static Process startProcess(ProcessBuilder pb) throws IOException {
    try {
        return pb.start();
    } catch (IOException e) {
        IOException toThrow = new IOException(ExceptionMessageMap.getMessage("020100"));
        toThrow.initCause(e);
        throw toThrow;
    }
}

From source file:myproject.Model.Common.ProcessExecutor.java

private static String properExecute(File file, String... commands) throws IOException, InterruptedException {
    ProcessBuilder builder = new ProcessBuilder(commands);
    if (file != null) {
        builder.directory(file);//from ww  w .  j  a  v  a  2  s.  c  om
    }
    Process process = builder.start();
    String input = IOUtils.toString(process.getInputStream(), "utf-8");
    String error = IOUtils.toString(process.getErrorStream(), "utf-8");
    //String command = Arrays.toString(builder.command().toArray(new String[] {}));
    process.waitFor();
    process.getInputStream().close();
    if (!error.isEmpty()) {
        Log.errorLog(error, ProcessExecutor.class);
    }
    String result = input;
    if (input.isEmpty()) {
        result = error;
    }
    return result;
}

From source file:alluxio.cli.AlluxioFrameworkIntegrationTest.java

private static void stopAlluxioFramework() throws Exception {
    String stopScript = PathUtils.concatPath(Configuration.get(PropertyKey.HOME), "integration", "mesos", "bin",
            "alluxio-mesos-stop.sh");
    ProcessBuilder pb = new ProcessBuilder(stopScript);
    pb.start().waitFor();
    // Wait for Mesos to unregister and shut down the Alluxio Framework.
    CommonUtils.sleepMs(5000);/* ww w . j a  v  a  2  s.c o m*/
}

From source file:JMeterProcessing.JMeterPropertiesGenerator.java

private static void doCurl(String url, String[] idNames, Map<String, Long> idValuesMap)
        throws JSONException, IOException {
    String[] command = { "curl", "-H", "Accept:application/json", "-X", "GET", "-u",
            _USERNAME + ":" + _PASSWORD, url };

    ProcessBuilder process = new ProcessBuilder(command);

    Process p = process.start();

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

    StringBuilder sb = new StringBuilder();

    String line = reader.readLine();

    while (line != null) {
        sb.append(line);//from  ww w .  jav  a  2s  . c o  m

        line = reader.readLine();
    }

    String result = sb.toString();

    if (result != null) {
        JSONObject curlResult = new JSONObject(result);

        JSONObject jsonObject;

        try {
            JSONArray data = curlResult.getJSONArray("data");

            jsonObject = data.getJSONObject(0);
        } catch (JSONException e) {
            jsonObject = curlResult.getJSONObject("data");
        }

        for (String idName : idNames) {
            Long idValue = jsonObject.getLong(idName);

            idValuesMap.put(idName, idValue);
        }
    }
}

From source file:alluxio.cli.AlluxioFrameworkIntegrationTest.java

private static void stopAlluxio() throws Exception {
    String stopScript = PathUtils.concatPath(Configuration.get(PropertyKey.HOME), "bin", "alluxio-stop.sh");
    ProcessBuilder pb = new ProcessBuilder(stopScript, "all");
    pb.start().waitFor();
}

From source file:com.microsoft.alm.plugin.idea.common.setup.WindowsStartup.java

/**
 * Run script to launch elevated process to create registry keys
 *
 * @param regeditFilePath/*www.  j  a v a  2s.  co  m*/
 */
private static void launchElevatedCreation(final String regeditFilePath) {
    try {
        final String[] cmd = { "cmd", "/C", "regedit", "/s", regeditFilePath };
        final ProcessBuilder processBuilder = new ProcessBuilder(cmd);
        final Process process = processBuilder.start();
        process.waitFor();
    } catch (IOException e) {
        logger.warn("Running regedit encountered an IOException: {}", e.getMessage());
    } catch (Exception e) {
        logger.warn("Waiting for the process to execute resulted in an error: " + e.getMessage());
    }
}

From source file:edu.uci.ics.asterix.installer.test.AsterixClusterLifeCycleIT.java

private static Process invoke(String... args) throws Exception {
    ProcessBuilder pb = new ProcessBuilder(args);
    pb.redirectErrorStream(true);//from  www . j  a va  2s.c o m
    Process p = pb.start();
    return p;
}

From source file:net.chris54721.infinitycubed.utils.Utils.java

public static void restart() {
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override/*from  w  ww.ja v  a2s .c om*/
        public void run() {
            try {
                File executable = new File(URLDecoder.decode(
                        (Launcher.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()),
                        "UTF-8"));
                List<String> command = new ArrayList<String>();
                command.add(getJavaPath());
                command.add("-jar");
                command.add(executable.getAbsolutePath());
                ProcessBuilder builder = new ProcessBuilder(command);
                builder.start();
            } catch (Exception e) {
                LogHelper.error("Failed restarting launcher, shutting down", e);
                System.exit(-1);
            }
        }
    });
    System.exit(0);
}

From source file:io.ingenieux.lambda.shell.LambdaShell.java

private static void runCommandArray(OutputStream os, String... args) throws Exception {
    PrintWriter pw = new PrintWriter(os, true);

    File tempPath = File.createTempFile("tmp-", ".sh");

    IOUtils.write(StringUtils.join(args, " "), new FileOutputStream(tempPath));

    List<String> processArgs = new ArrayList<>(Arrays.asList("/bin/bash", "-x", tempPath.getAbsolutePath()));

    ProcessBuilder psBuilder = new ProcessBuilder(processArgs).//
            redirectErrorStream(true);//

    final Process process = psBuilder.start();

    final Thread t = new Thread(() -> {
        try {//from  w  w w  .  j a va2s  .  c  o m
            IOUtils.copy(process.getInputStream(), os);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });

    t.start();

    process.waitFor();

    t.join();

    int resultCode = process.exitValue();
}

From source file:kr.ac.kaist.wala.hybridroid.analysis.resource.AndroidDecompiler.java

private static void permission(String path) {
    String[] cmd = { "chmod", "755", path };
    ProcessBuilder pb = new ProcessBuilder();
    pb.command(cmd);/*  w  w  w .ja  va2  s.c  o m*/

    Process p = null;
    try {
        p = pb.start();
        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        String r = null;

        while ((r = br.readLine()) != null) {
            System.out.println(r);
        }

        while ((r = bre.readLine()) != null) {
            System.err.println(r);
        }

        int res = p.waitFor();
        if (res != 0) {
            throw new InternalError("failed to decompile: " + path);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}