CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2009
    Posts
    2

    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);
                }

  2. #2
    Join Date
    Mar 2009
    Posts
    8

    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.

  3. #3
    Join Date
    May 2009
    Posts
    2

    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.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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
  •  





Click Here to Expand Forum to Full Width

Featured