Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By masijade

Thread: Issues with waitFor () : Quick reply should be appreciated

  1. #1
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default Issues with waitFor () : Quick reply should be appreciated

    hi,

    This is regarding the threading.

    while I am trying to do bcp 19 files in the order , it is trying to start bcp the fist file and waiting for a long time and not even releasing.

    I dont know why p.waitFor() is going into indefinite loop.

    String prepareQuery = "cmd /c "+"c:\\sybase\\bin\\bcp "+archdatabasename+".."+tableName+" in "+processingDirectoryPath+"\\"+file_Name+" -S"+database+" -U"+username+" -P"+password+" -f "+"D:\\2048240\\mapfiles\\"+formatFileName+" -b"+batchCount;

    String cmd = prepareQuery;

    System.out.println(prepareQuery);
    Process p = Runtime.getRuntime().exec(cmd);

    p.waitFor();

    BufferedReader bcpoutput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

    String thisLine;
    while ((thisLine = bcpoutput.readLine()) != null) { // while loop begins here
    log.debug(thisLine);
    } // end while
    s = stdError.readLine();

    Err = p.exitValue();
    p.destroy();

    Thanks,
    Adithya

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: Issues with waitFor () : Quick reply should be appreciated

    Read this. It is old but still contains good information. For a second thing, I would advise changing to ProcessBuilder. The problem here is probably that the output/error buffer is filling up, and so the "execed" command will hang until it is able to write to them again, but it can't since you are not reading those until the program finishes. You need to read those in separate threads and start reading from them immediately, not when the program ends.
    gimbal2 likes this.

Similar Threads

  1. waitFor()
    By manou2324 in forum New To Java
    Replies: 0
    Last Post: 05-24-2013, 01:43 AM
  2. unzip.waitfor();?
    By IYIaster in forum New To Java
    Replies: 0
    Last Post: 04-17-2010, 05:28 AM
  3. Process.waitFor() method hangs application.
    By simmi in forum New To Java
    Replies: 2
    Last Post: 02-10-2010, 03:35 AM
  4. Please reply to help Me ......
    By mohamed sherif in forum New To Java
    Replies: 3
    Last Post: 12-02-2008, 07:05 PM

Posting Permissions

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