1

I want to start or stop two services in this order: service1 then service2. Here is my bat file(test.bat):
SET _cmd=net %1 service1 && net %1 service2
cmd /C %_cmd%

If run this bat like this: test.bat start or test.bat stop, the output looks as below:
starting/stopping service2
starting/stopping service1

However, what I want is service1 then service2. Could anybody show me how to do that?

If just run below command in a command prompt window, commands will run in right order:
cmd /c net stop service1 & net stop service2

Anybody know the differences? Thanks in advance!

1 Answer 1

3

Your batch file runs the two commands

SET _cmd=net %1 service1
net %1 service2

in that order. The && does not become part of _cmd. Then, you run

cmd /C %_cmd%

which starts service1.

It seems to me the easiest way to do what you want is:

net %1 service1 && net %1 service2

There is no need to involve cmd /c or an environment variable.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your clue! Seems you are right, maybe the SET line will run as you said. Change the SET line as below will work: SET _cmd="net %1 service1 && net %1 service2"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.