Results 1 to 2 of 2
  1. #1
    javameanslife is offline Member
    Join Date
    Jan 2010
    Rep Power

    Question How to use process builder

    I am working on a java program where I have to call another java program using process builder because it uses a separate JRE.

    Here is batch program which calls this program and works properly:

    cd C:\apps\Project_name\bin\
    C:\Progra~1\Java\jre1.6.0_03\bin\java -Xms512m -Xmx1024m -cp ../lib/spring-1.2.2.jar;../lib/log4j-1.2.8.jar;../lib/commons-logging-1.0.4.jar;../lib/wrapper.jar com.project.main.MainProgramLauncher arg1 arg2

    Now I declared my code something like this:

    ProcessBuilder builder = new ProcessBuilder("java", "-Xms512m","-Xmx1024m","-cp ../lib/spring-1.2.2.jar;../lib/log4j-1.2.8.jar;../lib/commons-logging-1.0.4.jar;../lib/wrapper.jar","com.project.main.MainProgramLauncher arg1 arg2 ...argN");
    Map<String, String> environment = builder.environment();

    environment.put("path", ";"); // Clearing the path variable;
    Process javap = builder.start();
    InputStreamReader tempReader = new InputStreamReader(
    new BufferedInputStream(javap.getInputStream()));
    BufferedReader reader = new BufferedReader(tempReader);
    while (true) {
    String line = reader.readLine();
    if (line == null)

    But its not executing the way it should be. The program crashing right away. Is there anything different I should be doing? Please suggest.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    Java Code:
    "-cp ../lib/spring-1.2.2.jar;../lib/log4j-1.2.8.jar;../lib/commons-logging-1.0.4.jar;../lib/wrapper.jar","com.project.main.MainProgramLauncher arg1 arg2 ...argN"
    should be this
    Java Code:
    "-cp", "../lib/spring-1.2.2.jar;../lib/log4j-1.2.8.jar;../lib/commons-logging-1.0.4.jar;../lib/wrapper.jar","com.project.main.MainProgramLauncher", "arg1", "arg2", "...argN"
    Edit: You also need to either redirect STDERR to STDOUT, or start another reader for the error stream (running in a separate thread). You would also be well served starting your reader in another thread and simply using waitFor in the main thread.
    Last edited by masijade; 01-21-2010 at 08:49 AM.

Similar Threads

  1. Builder
    By AgentApe in forum New To Java
    Replies: 4
    Last Post: 12-02-2009, 10:33 PM
  2. Replies: 1
    Last Post: 08-12-2009, 03:34 PM
  3. Formula Builder
    By rbs100 in forum Advanced Java
    Replies: 1
    Last Post: 07-03-2009, 07:57 PM
  4. Eclipse GUI Builder
    By elebal in forum Eclipse
    Replies: 1
    Last Post: 10-23-2008, 12:38 PM
  5. Help with NetBeans 5 GUI builder
    By Daniel in forum NetBeans
    Replies: 2
    Last Post: 07-04-2007, 08:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts