WaitFor() works only when in debugging mode!
Hi, im having a problem with making my function waits for a process to end while in run mode!
The function always run and exists while the process is still running...
I checked it in debugging mode and it worked just fine, but i cant seem to be able to make it work in the run mode!
Any hints?
Here is my code:
public void executeBatch (){
try{
Runtime runtime = Runtime.getRuntime();
Process batchProcess = runtime.exec(new String[] {"cmd.exe", "/c", "FetchFiles.bat"}, null, new File(BATCH_FILES_PATH));
BufferedReader b = new BufferedReader(new InputStreamReader(batchProcess.getErrorStream()));
if (b.ready()){
String line=null;
while ( (line = b.readLine()) != null) {
System.out.println(line);
line = b.readLine();
}
int exitVal = batchProcess.waitFor();
System.out.println("Exit Value = " + exitVal);
} else {
b = new BufferedReader(new InputStreamReader(batchProcess.getInputStream()));
if (b.ready()){
String line=null;
while ( (line = b.readLine()) != null) {
System.out.println(line);
line = b.readLine();
}
int exitVal = batchProcess.waitFor();
System.out.println("Exit Value = " + exitVal);
}
}
} catch ( Exception ex ){
System.out.println("executeBatch : " + ex.getMessage());
}
}
btw, the process is a batch that connects to a linux server and "mget" files from some directories in the server...

