Process waitFor not working?

K

Kevin

Hello,
I am not sure the way that I use the wairFor is right or not (under
WinXP).
The code looks like:

try
{
// print current time.
Process p = Runtime.getRuntime().exec(a_exe_file);
p.waitFor();
// print current time.
}
.......

a_exe_file is a C++ Win32 program which does some calculation.

Here comes the problem:
if I run it as above, I find it does not return (so the second print
time will never happen).

If I remove the p.wairFor() line, of cource, the java process continues
without wait for the a_exe_file to finish (so I see two print time).

I observed something here: from window's task manager, I can see that
in either case, it seems that the a_exe_file will sit in memory after
its work is done -- I can figure out this because a_exe_file is a CPU
eating program. Since it remains in memory even after its work is done,
I guess java will think it is still working so java will wait for
every.

If I run a_exe_file along under windows, it finishs and returns without
any problem. In this way, I am thinking if there is something wrong in
the way I call it from the java code? Why it does not return when
called from Java?

Thanks a lot.
 
K

Kevin

By the way, the external program a_exe_file does not output anything to
std out. It just reads a file, does some calculation, and writes out to
another file -- at least when I run it under windows it does so.
 

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

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,216
Latest member
topweb3twitterchannels

Latest Threads

Top