Example usage for java.lang Process waitFor

List of usage examples for java.lang Process waitFor

Introduction

In this page you can find the example usage for java.lang Process waitFor.

Prototype

public abstract int waitFor() throws InterruptedException;

Source Link

Document

Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.

Usage

From source file:com.twitter.hraven.hadoopJobMonitor.notification.Mail.java

public static void send(String subject, String msg, String to) {
    List<String> commands = new LinkedList<String>();
    commands.add("/bin/bash");
    commands.add("-c");
    commands.add("echo \"" + msg + "\" | mail -s \"" + subject + "\" " + to + "," + CC);
    //This option is not supported by all mail clients: + " -c " + CC);
    //This option is not supported by all mail clients: + " -- -f " + ADMIN);
    ProcessBuilder pb = new ProcessBuilder(commands);
    Process p;
    int exitValue = -1;
    try {/*from  w  ww.  ja va 2 s  .  c o  m*/
        p = pb.start();
        exitValue = p.waitFor();
        LOG.info("Send email to " + to + " exitValue is " + exitValue);
    } catch (IOException e) {
        LOG.error("Error in executing mail command", e);
    } catch (InterruptedException e) {
        LOG.error("Error in executing mail command", e);
    } finally {
        if (exitValue != 0) {
            LOG.fatal(commands);
            //        ExitUtil.terminate(1, "Could not send mail: " + "exitValue was "
            //            + exitValue);
        }
    }
}

From source file:com.att.voice.TTS.java

private static void executeOnCommandLine(final String command) {
    try {//from  w  w w . j a  va 2  s . c  o m
        System.out.println("%%% " + command + " %%%");

        Process process = Runtime.getRuntime().exec(command);
        process.waitFor();
    } catch (Exception e) {
        System.err.println("ERROR executing command " + command + " " + e);
    }
}

From source file:com.twitter.bazel.checkstyle.PythonCheckstyle.java

private static void runLinter(List<String> command) throws IOException {
    LOG.finer("checkstyle command: " + command);

    ProcessBuilder processBuilder = new ProcessBuilder(command);
    processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
    processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    Process pylint = processBuilder.start();

    try {/* w w  w  .  j  a v a2s . c om*/
        pylint.waitFor();
    } catch (InterruptedException e) {
        throw new RuntimeException("python checkstyle command was interrupted: " + command, e);
    }

    if (pylint.exitValue() == 30) {
        LOG.warning("python checkstyle detected bad styles.");
        // SUPPRESS CHECKSTYLE RegexpSinglelineJava
        System.exit(1);
    }

    if (pylint.exitValue() != 0) {
        throw new RuntimeException("python checkstyle command failed with status " + pylint.exitValue());
    }
}

From source file:ConsoleUtils.java

public static int execute(String command) throws InterruptedException, IOException {
    Process process = Runtime.getRuntime().exec(command);
    process.waitFor();
    return process.exitValue();
}

From source file:biomine.bmvis2.pipeline.sources.StreamGraphSource.java

public static StreamGraphSource getNodeExpandProgramGraphSource(final String expandProgramName, VisualNode node)
        throws IOException, InterruptedException, GraphOperationException {
    String nodeId = node.getId();
    String cmd = expandProgramName + " " + nodeId;
    Logging.debug("expand", "Running command: " + cmd);
    Runtime run = Runtime.getRuntime();
    Process pr = run.exec(cmd);
    pr.waitFor();

    StreamGraphSource s = new StreamGraphSource(pr.getInputStream(), "Neighborhood for " + nodeId);
    StreamGraphSource.assignPositions(s.getBMGraph(), node);
    return s;// w w w  . ja  v  a  2  s  . c o m
}

From source file:com.twitter.bazel.checkstyle.CppCheckstyle.java

private static void runLinter(List<String> command) throws IOException {
    LOG.fine("checkstyle command: " + command);

    ProcessBuilder processBuilder = new ProcessBuilder(command);
    processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
    processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
    Process cpplint = processBuilder.start();

    try {//w  ww.ja  va 2 s .c o  m
        cpplint.waitFor();
    } catch (InterruptedException e) {
        throw new RuntimeException("cpp checkstyle command was interrupted: " + command, e);
    }

    if (cpplint.exitValue() == 1) {
        LOG.warning("cpp checkstyle detected bad styles.");
        // SUPPRESS CHECKSTYLE RegexpSinglelineJava
        System.exit(1);
    }

    if (cpplint.exitValue() != 0) {
        throw new RuntimeException("cpp checkstyle command failed with status " + cpplint.exitValue());
    }
}

From source file:Main.java

public static void openBar() {
    Process proc;
    try {/*from   w  w w  .j  a  v a 2s  . c om*/
        proc = Runtime.getRuntime().exec("am startservice --user 0 -n com.android.systemui/.SystemUIService");
        proc.waitFor();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.qwazr.utils.process.ProcessUtils.java

public static Integer run(String commandLine) throws InterruptedException, IOException {
    Process process = Runtime.getRuntime().exec(commandLine);
    try {//from   w w  w . j  a  va  2s. co m
        return process.waitFor();
    } finally {
        process.destroy();
        if (process.isAlive())
            process.destroyForcibly();
    }
}

From source file:ConsoleUtils.java

public static Process exec(String command[], boolean stop) throws InterruptedException, IOException {
    Process p = Runtime.getRuntime().exec(command);
    if (stop)/*from   ww  w.j  a va  2 s .c  o  m*/
        p.waitFor();
    return p;
}

From source file:com.googlecode.promnetpp.research.main.CompareOutputMain.java

private static void doSeedRun(int seed) throws IOException, InterruptedException {
    System.out.println("Running with seed " + seed);
    String pattern = "int random = <INSERT_SEED_HERE>;";
    int start = sourceCode.indexOf(pattern);
    int end = start + pattern.length();
    String line = sourceCode.substring(start, end);
    line = line.replace("<INSERT_SEED_HERE>", Integer.toString(seed));
    String sourceCodeWithSeed = sourceCode.replace(pattern, line);
    File tempFile = new File("temp.pml");
    FileUtils.writeStringToFile(tempFile, sourceCodeWithSeed);
    //Create a "project" folder
    String fileNameWithoutExtension = fileName.split("[.]")[0];
    File folder = new File("test1-" + fileNameWithoutExtension);
    if (folder.exists()) {
        FileUtils.deleteDirectory(folder);
    }/* ww w .  j a v a 2s  .co m*/
    folder.mkdir();
    //Copy temp.pml to our new folder
    FileUtils.copyFileToDirectory(tempFile, folder);
    //Simulate the model using Spin
    List<String> spinCommand = new ArrayList<String>();
    spinCommand.add(GeneralData.spinHome + "/spin");
    spinCommand.add("-u1000000");
    spinCommand.add("temp.pml");
    ProcessBuilder processBuilder = new ProcessBuilder(spinCommand);
    processBuilder.directory(folder);
    processBuilder.redirectOutput(new File(folder, "spin-" + seed + ".txt"));
    Process process = processBuilder.start();
    process.waitFor();
    //Translate via PROMNeT++
    List<String> PROMNeTppCommand = new ArrayList<String>();
    PROMNeTppCommand.add("java");
    PROMNeTppCommand.add("-enableassertions");
    PROMNeTppCommand.add("-jar");
    PROMNeTppCommand.add("\"" + GeneralData.getJARFilePath() + "\"");
    PROMNeTppCommand.add("temp.pml");
    processBuilder = new ProcessBuilder(PROMNeTppCommand);
    processBuilder.directory(folder);
    processBuilder.environment().put("PROMNETPP_HOME", GeneralData.PROMNeTppHome);
    process = processBuilder.start();
    process.waitFor();
    //Run opp_makemake
    FileUtils.copyFileToDirectory(new File("opp_makemake.bat"), folder);
    List<String> makemakeCommand = new ArrayList<String>();
    if (Utilities.operatingSystemType.equals("windows")) {
        makemakeCommand.add("cmd");
        makemakeCommand.add("/c");
        makemakeCommand.add("opp_makemake.bat");
    } else {
        throw new RuntimeException("Support for Linux/OS X not implemented" + " here yet.");
    }
    processBuilder = new ProcessBuilder(makemakeCommand);
    processBuilder.directory(folder);
    process = processBuilder.start();
    process.waitFor();
    //Run make
    FileUtils.copyFileToDirectory(new File("opp_make.bat"), folder);
    List<String> makeCommand = new ArrayList<String>();
    if (Utilities.operatingSystemType.equals("windows")) {
        makeCommand.add("cmd");
        makeCommand.add("/c");
        makeCommand.add("opp_make.bat");
    } else {
        throw new RuntimeException("Support for Linux/OS X not implemented" + " here yet.");
    }
    processBuilder = new ProcessBuilder(makeCommand);
    processBuilder.directory(folder);
    process = processBuilder.start();
    process.waitFor();
    System.out.println(Utilities.getStreamAsString(process.getInputStream()));
    System.exit(1);
}