0

I've just started using Inno Setup and I have come across a problem where I need to stop and start tomcat using the cmd. However, using the solution i am using is not working for some reason.

What I am trying to accomplish is to.

  1. Stop tomcat using "net stop tomcat6"
  2. Write a string to a xml-file in the tomcat folder.
  3. Start tomcat using "net start tomcat6"

The solution I am trying with is:

if Exec(ExpandConstant('{cmd}'), '/c net stop tomcat6', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
    begin
      Log('Result code is: ' + IntToStr(ResultCode));
      SaveStringToFile(dirPage.Values[0] + '\conf\Catalina\localhost\' + inputPage.Values[0] + '.xml', GenerateXmlString(inputPage.Values[0], inputPage.Values[1], inputPage.Values[2], 
                                                                                         inputPage.Values[3], inputPage.Values[4], inputPage.Values[5], 
                                                                                         inputPage.Values[6]), False);
      Exec(ExpandConstant('{cmd}'), '/c net start tomcat6', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
    end

This however doesn't seem like the right way to go about this problem since is doesn't stop nor start the tomcat service.

These commands works perfectly if I write them manually in the cmd-window.

Sincerely,

LosGlennos
  • 99
  • 10
  • What returns the `ResultCode` variable ? – TLama Oct 07 '13 at 11:42
  • ResultCode is 2. I've investigated further and apparently the tomcat service stops as it should, so the Exec-command works. The problem is elsewhere. It may be that the service doesn't terminate all the way before I try to start it up again, and that it could cause the problems I'm having. Any thoughts? – LosGlennos Oct 07 '13 at 11:49
  • Yes, that might be problem. I'm afraid the command line returns immediately after it runs `net stop`. It doesn't wait until the service is actually stopped as you say. A solution ? Use Windows Service API. I should have finished an example for controlling Windows Services from Inno Setup, but I forgot. It's frequently asked question. Here is just, [`how to install service`](http://stackoverflow.com/a/15235687/960757), which is not useful for you. Quite easily such code might be extended to start and stop services, but I need some extra time for that, which I don't have right now. – TLama Oct 07 '13 at 11:53
  • 1
    Okay, thank you. I will investigate this and post a solution when I figure it out! – LosGlennos Oct 07 '13 at 11:58

0 Answers0