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

    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;
    environment.put("path",
    java_bin_location+";");
    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)
    break;
    System.out.println(line);
    }

    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
    Posts
    2,571
    Rep Power
    9

    Default

    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"
    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 07:49 AM.

Similar Threads

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