Java Code Examples for java.lang.Process#waitFor()

The following examples show how to use java.lang.Process#waitFor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DaCapoClientRunner.java    From dacapobench with Apache License 2.0 7 votes vote down vote up
public static void initialize(String carName, String size, int numThreads, boolean useBeans) {
  try {

    car = carName;

    /* Calling this function directly does not launch the client now. According to testing, it seems the getMain method of boot does not work properlly.
       Thus these ugly codes are temporarily used fot verifing that the whole framework works
       Will be changed once the problem is fixed
    */
    //ClientCLI.main(new String[] { car, "-i", "-t", numThreads + "", "-s", size, useBeans ? "-b" : "" });


    gero = System.getProperty("org.apache.geronimo.home.dir");
    String jhome= System.getProperty("java.home");
    ProcessBuilder pb = new ProcessBuilder(jhome + "/bin/java", "-jar", "-Dkaraf.startLocalConsole=false",gero + "/bin/client.jar", car, "-i", "-t", numThreads + "", "-s", size, useBeans ? "-b" : "");
    Process p = pb.start();
    p.waitFor();

  } catch (Exception e) {
    System.err.print("Exception initializing client: " + e.toString());
    e.printStackTrace();
    System.exit(-1);
  }
}
 
Example 2
Source File: MXBeanWeirdParamTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs MXBeanWeirdParamTest$ClientSide with the passed options and redirects
 * subprocess standard I/O to the current (parent) process. This provides a
 * trace of what happens in the subprocess while it is runnning (and before
 * it terminates).
 *
 * @param serviceUrlStr string representing the JMX service Url to connect to.
 */
private int runClientSide(String serviceUrlStr) throws Exception {

    // Building command-line
    List<String> opts = buildCommandLine();
    opts.add(serviceUrlStr);

    // Launch separate JVM subprocess
    int exitCode = 0;
    String[] optsArray = opts.toArray(new String[0]);
    ProcessBuilder pb = new ProcessBuilder(optsArray);
    Process p = ProcessTools.startProcess("MXBeanWeirdParamTest$ClientSide", pb);

    // Handling end of subprocess
    try {
        exitCode = p.waitFor();
        if (exitCode != 0) {
            System.out.println(
                "Subprocess unexpected exit value of [" + exitCode +
                "]. Expected 0.\n");
        }
    } catch (InterruptedException e) {
        System.out.println("Parent process interrupted with exception : \n " + e + " :" );

        // Parent thread unknown state, killing subprocess.
        p.destroyForcibly();

        throw new RuntimeException(
            "Parent process interrupted with exception : \n " + e + " :" );
    } finally {
        return exitCode;
    }

 }
 
Example 3
Source File: MXBeanWeirdParamTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs MXBeanWeirdParamTest$ClientSide with the passed options and redirects
 * subprocess standard I/O to the current (parent) process. This provides a
 * trace of what happens in the subprocess while it is runnning (and before
 * it terminates).
 *
 * @param serviceUrlStr string representing the JMX service Url to connect to.
 */
private int runClientSide(String serviceUrlStr) throws Exception {

    // Building command-line
    List<String> opts = buildCommandLine();
    opts.add(serviceUrlStr);

    // Launch separate JVM subprocess
    int exitCode = 0;
    String[] optsArray = opts.toArray(new String[0]);
    ProcessBuilder pb = new ProcessBuilder(optsArray);
    Process p = ProcessTools.startProcess("MXBeanWeirdParamTest$ClientSide", pb);

    // Handling end of subprocess
    try {
        exitCode = p.waitFor();
        if (exitCode != 0) {
            System.out.println(
                "Subprocess unexpected exit value of [" + exitCode +
                "]. Expected 0.\n");
        }
    } catch (InterruptedException e) {
        System.out.println("Parent process interrupted with exception : \n " + e + " :" );

        // Parent thread unknown state, killing subprocess.
        p.destroyForcibly();

        throw new RuntimeException(
            "Parent process interrupted with exception : \n " + e + " :" );
    } finally {
        return exitCode;
    }

 }
 
Example 4
Source File: MXBeanWeirdParamTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs MXBeanWeirdParamTest$ClientSide with the passed options and redirects
 * subprocess standard I/O to the current (parent) process. This provides a
 * trace of what happens in the subprocess while it is runnning (and before
 * it terminates).
 *
 * @param serviceUrlStr string representing the JMX service Url to connect to.
 */
private int runClientSide(String serviceUrlStr) throws Exception {

    // Building command-line
    List<String> opts = buildCommandLine();
    opts.add(serviceUrlStr);

    // Launch separate JVM subprocess
    int exitCode = 0;
    String[] optsArray = opts.toArray(new String[0]);
    ProcessBuilder pb = new ProcessBuilder(optsArray);
    Process p = ProcessTools.startProcess("MXBeanWeirdParamTest$ClientSide", pb);

    // Handling end of subprocess
    try {
        exitCode = p.waitFor();
        if (exitCode != 0) {
            System.out.println(
                "Subprocess unexpected exit value of [" + exitCode +
                "]. Expected 0.\n");
        }
    } catch (InterruptedException e) {
        System.out.println("Parent process interrupted with exception : \n " + e + " :" );

        // Parent thread unknown state, killing subprocess.
        p.destroyForcibly();

        throw new RuntimeException(
            "Parent process interrupted with exception : \n " + e + " :" );
    } finally {
        return exitCode;
    }

 }
 
Example 5
Source File: MXBeanWeirdParamTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs MXBeanWeirdParamTest$ClientSide with the passed options and redirects
 * subprocess standard I/O to the current (parent) process. This provides a
 * trace of what happens in the subprocess while it is runnning (and before
 * it terminates).
 *
 * @param serviceUrlStr string representing the JMX service Url to connect to.
 */
private int runClientSide(String serviceUrlStr) throws Exception {

    // Building command-line
    List<String> opts = buildCommandLine();
    opts.add(serviceUrlStr);

    // Launch separate JVM subprocess
    int exitCode = 0;
    String[] optsArray = opts.toArray(new String[0]);
    ProcessBuilder pb = new ProcessBuilder(optsArray);
    Process p = ProcessTools.startProcess("MXBeanWeirdParamTest$ClientSide", pb);

    // Handling end of subprocess
    try {
        exitCode = p.waitFor();
        if (exitCode != 0) {
            System.out.println(
                "Subprocess unexpected exit value of [" + exitCode +
                "]. Expected 0.\n");
        }
    } catch (InterruptedException e) {
        System.out.println("Parent process interrupted with exception : \n " + e + " :" );

        // Parent thread unknown state, killing subprocess.
        p.destroyForcibly();

        throw new RuntimeException(
            "Parent process interrupted with exception : \n " + e + " :" );
    } finally {
        return exitCode;
    }

 }
 
Example 6
Source File: MXBeanWeirdParamTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs MXBeanWeirdParamTest$ClientSide with the passed options and redirects
 * subprocess standard I/O to the current (parent) process. This provides a
 * trace of what happens in the subprocess while it is runnning (and before
 * it terminates).
 *
 * @param serviceUrlStr string representing the JMX service Url to connect to.
 */
private int runClientSide(String serviceUrlStr) throws Exception {

    // Building command-line
    List<String> opts = buildCommandLine();
    opts.add(serviceUrlStr);

    // Launch separate JVM subprocess
    int exitCode = 0;
    String[] optsArray = opts.toArray(new String[0]);
    ProcessBuilder pb = new ProcessBuilder(optsArray);
    Process p = ProcessTools.startProcess("MXBeanWeirdParamTest$ClientSide", pb);

    // Handling end of subprocess
    try {
        exitCode = p.waitFor();
        if (exitCode != 0) {
            System.out.println(
                "Subprocess unexpected exit value of [" + exitCode +
                "]. Expected 0.\n");
        }
    } catch (InterruptedException e) {
        System.out.println("Parent process interrupted with exception : \n " + e + " :" );

        // Parent thread unknown state, killing subprocess.
        p.destroyForcibly();

        throw new RuntimeException(
            "Parent process interrupted with exception : \n " + e + " :" );
    } finally {
        return exitCode;
    }

 }
 
Example 7
Source File: DaCapoClientRunner.java    From dacapobench with Apache License 2.0 5 votes vote down vote up
public static void runIteration(String size, int numThreads, boolean useBeans) {

    try {

      /* Calling the function directly does not launch the client now. According to testing, it seems the getMain method of boot does not work properlly.
         Thus these ugly codes are temporarily used for checking the whole framework
         Will be changed once the problem is fixed
      */
      //ClientCLI.main(new String[] { car, "-i", "-t", numThreads + "", "-s", size, useBeans ? "-b" : "" });

      String jhome= System.getProperty("java.home");

      ProcessBuilder pb = new ProcessBuilder(jhome + "/bin/java", "-jar", "-Dkaraf.startLocalConsole=false", gero + "/bin/client.jar", car, "-t", numThreads + "", "-s", size, useBeans ? "-b" : "");
      Process p = pb.start();
      p.waitFor();

      BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
      while (stdInput.ready()) { //While there's something in the buffer
        //read&print - replace with a buffered read (into an array) if the output doesn't contain CR/LF
        System.out.println(stdInput.readLine());
      }

    } catch (Exception e) {
      System.err.print("Exception running client iteration: " + e.toString());
      e.printStackTrace();
    }
  }
 
Example 8
Source File: MXBeanWeirdParamTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs MXBeanWeirdParamTest$ClientSide with the passed options and redirects
 * subprocess standard I/O to the current (parent) process. This provides a
 * trace of what happens in the subprocess while it is runnning (and before
 * it terminates).
 *
 * @param serviceUrlStr string representing the JMX service Url to connect to.
 */
private int runClientSide(String serviceUrlStr) throws Exception {

    // Building command-line
    List<String> opts = buildCommandLine();
    opts.add(serviceUrlStr);

    // Launch separate JVM subprocess
    int exitCode = 0;
    String[] optsArray = opts.toArray(new String[0]);
    ProcessBuilder pb = new ProcessBuilder(optsArray);
    Process p = ProcessTools.startProcess("MXBeanWeirdParamTest$ClientSide", pb);

    // Handling end of subprocess
    try {
        exitCode = p.waitFor();
        if (exitCode != 0) {
            System.out.println(
                "Subprocess unexpected exit value of [" + exitCode +
                "]. Expected 0.\n");
        }
    } catch (InterruptedException e) {
        System.out.println("Parent process interrupted with exception : \n " + e + " :" );

        // Parent thread unknown state, killing subprocess.
        p.destroyForcibly();

        throw new RuntimeException(
            "Parent process interrupted with exception : \n " + e + " :" );
    } finally {
        return exitCode;
    }

 }
 
Example 9
Source File: RepairnatorPostBuild.java    From repairnator with MIT License 5 votes vote down vote up
public void runRepairnator(EnvVars env) throws IOException,InterruptedException{
    Config config = this.config;
    System.out.println("jar location " + config.getJarLocation());
    RepairnatorProcessBuilder repProcBuilder = new RepairnatorProcessBuilder()
                                    .useJavaExec(config.getJavaExec())
                                    .atJarLocation(config.getJarLocation())
                                    .onGitUrl(config.getGitUrl())
                                    .onGitBranch(config.getGitBranch())
                                    .onGitOAuth(config.getGitOAuth())
                                    .withSmtpUsername(config.getSmtpUsername())
                                    .withSmtpPassword(config.getSmtpPassword())
                                    .withSmtpServer(config.getSmtpServer())
                                    .withSmtpPort(config.getSmtpPort())
                                    .shouldNotifyTo(config.getNotifyTo())
                                    .withRepairTools(config.getTools())
                                    .withSonarRules(config.getSonarRules())
                                    .useSmtpTls(config.useTLSOrSSL())
                                    .asNoTravisRepair()
                                    .alsoCreatePR()
                                    .withMavenHome(config.getMavenHome())
                                    .atWorkSpace(config.getTempDir().getAbsolutePath())
                                    .withOutputDir(config.getTempDir().getAbsolutePath());

    ProcessBuilder builder = repProcBuilder.build().directory(config.getTempDir());
    builder.redirectErrorStream(true);
    builder.inheritIO().redirectOutput(ProcessBuilder.Redirect.PIPE);
    Process process = builder.start();
    this.printProcessOutPut(process);
    process.waitFor();
}
 
Example 10
Source File: MXBeanWeirdParamTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs MXBeanWeirdParamTest$ClientSide with the passed options and redirects
 * subprocess standard I/O to the current (parent) process. This provides a
 * trace of what happens in the subprocess while it is runnning (and before
 * it terminates).
 *
 * @param serviceUrlStr string representing the JMX service Url to connect to.
 */
private int runClientSide(String serviceUrlStr) throws Exception {

    // Building command-line
    List<String> opts = buildCommandLine();
    opts.add(serviceUrlStr);

    // Launch separate JVM subprocess
    int exitCode = 0;
    String[] optsArray = opts.toArray(new String[0]);
    ProcessBuilder pb = new ProcessBuilder(optsArray);
    Process p = ProcessTools.startProcess("MXBeanWeirdParamTest$ClientSide", pb);

    // Handling end of subprocess
    try {
        exitCode = p.waitFor();
        if (exitCode != 0) {
            System.out.println(
                "Subprocess unexpected exit value of [" + exitCode +
                "]. Expected 0.\n");
        }
    } catch (InterruptedException e) {
        System.out.println("Parent process interrupted with exception : \n " + e + " :" );

        // Parent thread unknown state, killing subprocess.
        p.destroyForcibly();

        throw new RuntimeException(
            "Parent process interrupted with exception : \n " + e + " :" );
    } finally {
        return exitCode;
    }

 }
 
Example 11
Source File: derbyrunjartest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private static void runtool(jvm jvm, String loc, String[] args)
    throws IOException
{
    System.out.println(concatenate(args) + ':');

    if (jvm == null) {
        com.pivotal.gemfirexd.internal.iapi.tools.run.main(args);
        return;
    }

    Vector cmd = jvm.getCommandLine();
    cmd.addElement("-jar");
    cmd.addElement(loc);
    for (int i=0; i < args.length; i++) {
        cmd.addElement(args[i]);
    }
    String command = concatenate((String[]) cmd.toArray(new String[0]));

    Process pr = null;

    try
    {
        pr = Runtime.getRuntime().exec(command);
        BackgroundStreamSaver saver = 
                    new BackgroundStreamSaver(pr.getInputStream(), System.out);
        saver.finish();
        pr.waitFor();
        pr.destroy();
    } catch(Throwable t) {
        System.out.println("Process exception: " + t.getMessage());
        if (pr != null)
        {
            pr.destroy();
            pr = null;
        }
    }
}
 
Example 12
Source File: derbyrunjartest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private static void runtool(jvm jvm, String loc, String[] args)
    throws IOException
{
    System.out.println(concatenate(args) + ':');

    if (jvm == null) {
        com.pivotal.gemfirexd.internal.iapi.tools.run.main(args);
        return;
    }

    Vector cmd = jvm.getCommandLine();
    cmd.addElement("-jar");
    cmd.addElement(loc);
    for (int i=0; i < args.length; i++) {
        cmd.addElement(args[i]);
    }
    String command = concatenate((String[]) cmd.toArray(new String[0]));

    Process pr = null;

    try
    {
        pr = Runtime.getRuntime().exec(command);
        BackgroundStreamSaver saver = 
                    new BackgroundStreamSaver(pr.getInputStream(), System.out);
        saver.finish();
        pr.waitFor();
        pr.destroy();
    } catch(Throwable t) {
        System.out.println("Process exception: " + t.getMessage());
        if (pr != null)
        {
            pr.destroy();
            pr = null;
        }
    }
}