1
votes

One of my msbuild targets works as following:

  1. get configuration files
  2. start window service with those configuration files
  3. exec service specific task
  4. stop window service
  5. repeat

The issue is that sometimes service stop executable task (Exec Command="sc stop myservice") takes longer time and when "sc start myservice" is called it says that service is already running. So my question is: how can I wait for "exec" command ot finish? I tried to put each executable in target and call with "CallTarget" and putting appropriate "DependsOnTargets" or "AfterTargets" and it didn't work. Can you help me? Thanks in advance.

1
Exec does wait until the command is finished - stijn
The problem was that Exec actually did finished command execution (he simply thrown "sc stop myservice") and after that another exec started to work. I added timeout for the "sc start myservice" for a minute and it solved. - Array
So the problem wasn't really with Exec, but rather with sc? - stijn
Yes, strange however, I thought that Exec will wait for full execution of command, but it seems that Exec is not waiting for final "return" of the command. - Array
Hmm I assumed the problem was that sc stop returns before the service is really stopped, hence Exec also returns immediately (because it does wait for full execution, but in this case 'full' isn't emough for you) - stijn

1 Answers

0
votes

The problem was that Exec actually did finished command execution (he simply thrown "sc stop myservice") and after that another exec started to work. I added timeout for the "sc start myservice" for a minute and it solved. The result looked like:

<Exec Command="sc stop myservice" ContinueOnError="true" />
<Exec Command="sc start myservice" ContinueOnError="true" Timeout="60000" />