-
May 19th, 2009, 11:08 AM
#1
Calling JAR file hangs Process
.NET version: 2.0
Platform: Windows XP, SP2
Compiler: VS2005
Problem:
I call a JAR file using a Process by first passing in a ProcessInfo object. The JAR file runs successfully, however, the java.exe process does not terminate even when consuming ~0 CPU cycles. Hence a call to Process::waitForExit() hangs my program. Anyone run into this sort of problem?
Code:
Code:
ProcessStartInfo AcSPInfo = new ProcessStartInfo("\"C:\\Program Files\\Java\\jre1.6.0_07\\bin\\java.exe\"",
" -jar C:\\Workspace\\Scratch\\AcSP.jar");
AcSPInfo.WorkingDirectory = "C:\\Workspace\\Scratch";
AcSPInfo.RedirectStandardError = false;
AcSPInfo.RedirectStandardInput = false;
AcSPInfo.RedirectStandardOutput = true;
AcSPInfo.CreateNoWindow = true;
AcSPInfo.UseShellExecute = false;
Process AcSP = new Process();
AcSP.StartInfo = AcSPInfo;
try
{
AcSP.Start();
StreamReader output = AcSP.StandardOutput;
AcSP.WaitForExit(); //la la la, when will you finish!?
Console.Out.Write(output.ReadToEnd());
}
catch (Exception e)
{
Console.Out.WriteLine(e.Message);
}
-
May 19th, 2009, 11:43 AM
#2
Re: Calling JAR file hangs Process
I hate java. It's way too easy to break the Java.exe process. I almost shudder anytime I have to use a web app that uses Java. My only advice is to look at the java log console to see what it might be hanging on.
-
May 19th, 2009, 12:52 PM
#3
Re: Calling JAR file hangs Process
Looks like I found the solution to my problems:
http://cleancode.sourceforge.net/api...ecProcess.html
wonderful little bit of code this fellow wrote.
-
May 19th, 2009, 03:26 PM
#4
Re: Calling JAR file hangs Process
Another option is to use the WaitForExit( int timeout ) overload. This will wait for the process to finish up to the specified timeout value.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|