Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2005

Tip: Looking for answers? Try searching our database.

Process waitFor not working?

Thread view: 
Kevin - 31 Mar 2005 07:23 GMT
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.
Kevin - 31 Mar 2005 07:34 GMT
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.
Kevin - 31 Mar 2005 07:45 GMT
OK. Problem solved. Just in case it may benefit someone else:

The key:
don't belive a program will not output anything even when you run it
under windows it does not. Windows hide it from me!

The solution is at:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

Have fun.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.