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...

[1521 byte] By [Steve_joa] at [2007-10-3 11:15:25]
# 1

Edit: Oops...Didn't read the whole code...

A suggestion that might solve your problem is to run the Output on another thread, so your code isn't so cluttered, then it might be easier to identify the problem.

Btw, why are your if-else statements almost same?

Message was edited by:

atoxic

atoxica at 2007-7-15 13:39:30 > top of Java-index,Desktop,Developing for the Desktop...