Results 1 to 3 of 3
  1. #1
    simmi is offline Member
    Join Date
    Apr 2009
    Posts
    29
    Rep Power
    0

    Default Process.waitFor() method hangs application.

    Hi,

    I am executing Unix command "ps -ef" from Java using Runtime and Process.waitFor() method as shown in the code below. It works fine on our local enviornment but at the client side application hangs after waitFor() method. What could be the possible reason for this.

    boolean exeCommand() {
    String command = new String();
    String psgOut, pargsOut;
    StringTokenizer strtok;
    Integer pid;
    int i;
    Process psg, pargs;
    command = "ps -ef";
    try {
    psg = Runtime.getRuntime().exec(command);
    System.out.println("Before waitFor");
    i = psg.waitFor();
    System.out.println("After waitFor");
    if (i != 0) {
    return false;
    } else {
    BufferedReader psgInput = new BufferedReader(
    new InputStreamReader(psg.getInputStream()));
    while ((psgOut = psgInput.readLine()) != null) {
    if (psgOut.contains("test")) {
    return true;
    }
    }
    }
    } catch (Exception exp) {
    System.out.println("Exception");
    }
    return false;
    }

    Thanks in Advance.
    Simmi

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

  3. #3
    simmi is offline Member
    Join Date
    Apr 2009
    Posts
    29
    Rep Power
    0

    Default

    Hi,

    When I placed the statement i = psg.waitFor(); after reading the Input Stream it worked fine.So should we need to use waitfor() method or we can leave it.

    Simmi

Similar Threads

  1. NetBeans hangs on startup
    By peterme in forum NetBeans
    Replies: 1
    Last Post: 01-25-2010, 10:22 PM
  2. Replies: 4
    Last Post: 11-26-2009, 09:40 AM
  3. Program hangs
    By yuliada in forum Advanced Java
    Replies: 2
    Last Post: 11-11-2009, 03:58 AM
  4. Discussion: JVM hangs
    By Arica in forum Advanced Java
    Replies: 5
    Last Post: 06-29-2009, 04:29 AM
  5. Disallow doPOST method in Sun Application server
    By prakash_sahoo in forum Advanced Java
    Replies: 5
    Last Post: 08-28-2008, 06:54 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
  •