Process.waitFor() blocks forever

J

John Smith

when I double click on test.cmd within Windows Explorer it runs and
terminates fine by itself.

When I try running test.cmd via Java with the following, then the
process blocks "forever" on eqsKM.waitFor()
Process eqsKM = java.lang.Runtime.getRuntime().exec("H:\\Programs\
\Murex EQT PROD\\test.cmd", null, workingDir);
int exitValue = eqsKM.waitFor();

I opened up Task Manager and I see an instance of cmd.exe with 00 CPU
usage.

Any suggestions on why the Java app blocks on
int exitValue = eqsKM.waitFor();

And how to fix the hanging?

Thanks.
 
A

Arne Vajhøj

when I double click on test.cmd within Windows Explorer it runs and
terminates fine by itself.

When I try running test.cmd via Java with the following, then the
process blocks "forever" on eqsKM.waitFor()
Process eqsKM = java.lang.Runtime.getRuntime().exec("H:\\Programs\
\Murex EQT PROD\\test.cmd", null, workingDir);
int exitValue = eqsKM.waitFor();

I opened up Task Manager and I see an instance of cmd.exe with 00 CPU
usage.

Any suggestions on why the Java app blocks on
int exitValue = eqsKM.waitFor();

And how to fix the hanging?

You should probably run CMD.EXE with your CMD file as argument.

You may need to read what the script writes.

Arne
 
D

Daniel Pitts

when I double click on test.cmd within Windows Explorer it runs and
terminates fine by itself.

When I try running test.cmd via Java with the following, then the
process blocks "forever" on eqsKM.waitFor()
Process eqsKM = java.lang.Runtime.getRuntime().exec("H:\\Programs\
\Murex EQT PROD\\test.cmd", null, workingDir);
int exitValue = eqsKM.waitFor();

I opened up Task Manager and I see an instance of cmd.exe with 00 CPU
usage.

Any suggestions on why the Java app blocks on
int exitValue = eqsKM.waitFor();

And how to fix the hanging?

Thanks.
One possibility is that you need to drain the stderr and stdout streams.
Also, it is often better to use ProcessBuilder, so arguments don't get
misinterpreted (like I suspect they are in this case.)
 
J

John Smith

One possibility is that you need to drain the stderr and stdout streams.
  Also, it is often better to use ProcessBuilder, so arguments don't get
misinterpreted (like I suspect they are in this case.)

Thanks - waitFor stopped hanging after I flushed stdout and stderr.
But why do I have to flush the stdout and stderr in order for the
process to continue?
 
D

Daniel Pitts

Thanks - waitFor stopped hanging after I flushed stdout and stderr.
But why do I have to flush the stdout and stderr in order for the
process to continue?
Because while stdout and stderr may be buffered, the buffer won't grow
to infinite size (OOM anyone?). Since the size is arbitrarily small,
you don't know how many bytes will be enough to "plug" that buffer.
When a buffer is full, it is often convenient to block writes to that
buffer until more space is available.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,059
Members
48,769
Latest member
Clifft

Latest Threads

Top