Results 1 to 2 of 2
- 09-24-2013, 12:54 PM #1
Member
- Join Date
- Aug 2013
- Posts
- 3
- Rep Power
- 0
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
- 09-24-2013, 01:38 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,568
- Rep Power
- 15
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.
Similar Threads
-
waitFor()
By manou2324 in forum New To JavaReplies: 0Last Post: 05-24-2013, 02:43 AM -
unzip.waitfor();?
By IYIaster in forum New To JavaReplies: 0Last Post: 04-17-2010, 06:28 AM -
Process.waitFor() method hangs application.
By simmi in forum New To JavaReplies: 2Last Post: 02-10-2010, 04:35 AM -
Please reply to help Me ......
By mohamed sherif in forum New To JavaReplies: 3Last Post: 12-02-2008, 08:05 PM
Bookmarks