2

`I have written a below code for running exe that presently is ran through windows service. I want to call it by java program. But i am getting below error in image. I dont know how to go through installutil or debug this error. Please help me on this.

` enter image description here

import java.io.*;

public class exec {
    public static void main(String[] args)throws Exception {
        try {
            String cmd = "D://OGLWindowsService//OGL_21052014//OGL_25_Feb_2015//OGLService.exe";
            Runtime run = Runtime.getRuntime();
            Process pr = run.exec(cmd); 
        }
        catch(Exception ex) {
            System.out.println(ex.getMessage());
        }
    }
}
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Mohit Darmwal
  • 275
  • 1
  • 5
  • 21
  • There is nothing wrong with your code. I think the problem is with your exe file which in my opinion is a windows service, so it can not be execute like this. – A.v Jun 14 '15 at 12:20
  • Nothing wrong with your code other than 1) it is all left justified making it hard to read, 2) you don't handle the Process's streams at all. – Hovercraft Full Of Eels Jun 14 '15 at 12:24
  • see this [Java Programming: call an exe from Java and passing parameters](http://stackoverflow.com/questions/5604698/java-programming-call-an-exe-from-java-and-passing-parameters). This might help you. – Bacteria Jun 14 '15 at 12:24
  • I have formatted your code for you. In the future, please take care to do this for us. – Hovercraft Full Of Eels Jun 14 '15 at 12:26
  • @Ali.Valizadeh yeah canty debug the prob...should i go for first installing windows service – Mohit Darmwal Jun 14 '15 at 12:28
  • Installutil is documented here https://msdn.microsoft.com/en-us/library/50614e95(v=vs.110).aspx What's confusing me is that it is a tool for installing .NET assemblies. I'm not sure it has any relevance to the Java world, although there won't be any harm in trying it. – Stephen Kennedy Jun 14 '15 at 12:37

1 Answers1

1

You actually have the answer for your question in your first screen. windows tells you that this program is designed to be the Service and could not run from the command line. It also suggests that you use insyalutil to set your program as a service and then Windows will run it when it will need it. Ususally service runs for some events. Most common - user connects to particular port associated with this service (for example port 80) and when such request occurs then Windows starts service progarm (IIS to answer http call) and delegate this request to this new program. Or delegeates it immediately if program is already running.

So, as you can see, Windows is in charge of the service programs. You cannot start them from command line of from another process (that's your example). You can start/stop/restart process manually in the service control window but that's still not command line or your process.

Alex
  • 4,457
  • 2
  • 20
  • 59
  • Nitpick: you can use the Windows-supplied commandline program `sc.exe` to do most if not all operations of `services.msc` -- and some "readonly" ones even without elevation/UAC when that is on. But you can't run a *service executable* from CMD, nor Java, nor doubleclicking in explorer etc. – dave_thompson_085 Jun 23 '15 at 15:25