How to call a java.exe through .Net Windows Service RRS feed

  • Question

  • Hi Friends,

    I have a problem in a Windows service ( .Net based ).

    In that service i'm creating one Process which call a batch file, contain a code to call a Java Console application.

    The above is working in a Windows application. The same code i'm trying in Windows service. It's not working.

    Here i have given  the code

     while (true)
                            Process mqBridgeProcess = new Process();
                            mqBridgeProcess.StartInfo.UseShellExecute = false;
                            mqBridgeProcess.StartInfo.RedirectStandardOutput = true;
                            ////mqBridgeProcess.StartInfo.FileName = "java";
                            ////mqBridgeProcess.StartInfo.Arguments = "hello 1 2 3";
                            mqBridgeProcess.StartInfo.FileName = "mqa.bat";
                            mqBridgeProcess.StartInfo.RedirectStandardInput = true;

                            mqBridgeProcess.StartInfo.Arguments = hostname + " " + channelName + " " + queueManagerName + " " + queueName + " " + port;
                            mqBridgeProcess.StartInfo.CreateNoWindow = true;
                            string output = mqBridgeProcess.StandardOutput.ReadToEnd();
                            logger.Info("File Name " + mqBridgeProcess.StartInfo.FileName);
                            logger.Info("Arguments " + mqBridgeProcess.StartInfo.Arguments);
                            logger.Info("MQSeries Output = " + output);
                            if (output != string.Empty)
                                string[] s1 = output.Split(new char[] { '\n' });
                                logger.Info("MQSeries Output Final = " + s1[5]);
                                finalOutput = s1[5];

                        catch (Exception MQExp)
                            logger.Debug("MQException Occured at GetMessage() Internal : " + MQExp.ToString());

    Batch File contain
    set classpath=%classpath%;%cd%\MQUtil.jar;%cd%\;%cd%\;%cd%\;%cd%\;.;
    java MQGet %1 %2 %3 %4 %5

    Please aqnyone give me the solution.  Its urgent

    S. Ramkumar.
    Friday, May 2, 2008 12:58 PM

All replies

  • You should set the service to interact with desktop.
    I believe that is only allowed if the local system account is used for the service to run under though.
    Friday, May 2, 2008 1:20 PM
  • Hi Jarrod,

    Thanks for your Immediate answer.

    I tried that also.  It's not working.

    The problem is when u run this through a windows application.  You can see a java.exe running in the task manager.

    But the same code i implemented in Windows service. it's not working.  i'm working on Windows2000 Operating System.

    Is there is any limitation to use these kind of service?

    S. Ramkumar

    Friday, May 2, 2008 1:28 PM
  • What can of error are you getting?  Can you please post the exception so we can better be able to help you.  Could the issue have something to to do with the user the process is running as?  Maybe the path variable needs to be set to java bin folder or something?  Please post the error message so we can help.

    Sunday, May 25, 2008 6:46 AM
  • If i'm not mistaken, by default, java will indead require interaction with your graphical system (in this case), it can be enabled by allowing interation with the destkop (but that is imho an ugly solution)..

    The other option is to launch java without a graphical system (if i'm not mistaken  you have to set the property java.awt.Headless, but don't know the command line arguments to pass in property values by heart... ))
    Tuesday, May 27, 2008 9:44 AM