Restart service with "&" or "&&&q
jibbajabba
Member Posts: 4,317 ■■■■■■■■□□
in Off-Topic
I always used several commands in one line using just one "&", but all references I can find online using two "&" - so "&&" ...
here is what i mean :
So it doesn't seem to make a difference .. or does it ?
here is what i mean :
C:\>net stop "DNS Server" & net start "DNS Server" The DNS Server service is stopping. The DNS Server service was stopped successfully. The DNS Server service is starting. The DNS Server service was started successfully. C:\>net stop "DNS Server" && net start "DNS Server" The DNS Server service is stopping. The DNS Server service was stopped successfully. The DNS Server service is starting. The DNS Server service was started successfully.
So it doesn't seem to make a difference .. or does it ?
My own knowledge base made public: http://open902.com
Comments
-
tiersten Member Posts: 4,505& = Run first command and then second command
&& = Run first command. If that is successful then run the second command. -
jibbajabba Member Posts: 4,317 ■■■■■■■■□□tiersten wrote:& = Run first command and then second command
&& = Run first command. If that is successful then run the second command.
Aaaah ... cheersMy own knowledge base made public: http://open902.com -
sprkymrk Member Posts: 4,884 ■■■□□□□□□□tiersten wrote:& = Run first command and then second command
&& = Run first command. If that is successful then run the second command.
This is 100% true, but be careful with the way you use it. The "&&" only interrprets whether or not the command completed successfully, and not necesarily that it DID what you wanted it to do.
For instance, in your example, the cmd to stop the DNS service might execute, but the result might be "Unable to stop DNS service" for whatever reason. Well the command ran, but it did not actually do what you wanted it to do, and the command to NET START DNS will attempt to execute. In this example, no real harm is done, but it illustrates the point.
I first ran into this using the "&&" with something like this (to use your example):
net stop "DNS Server" && echo DNS Server service stopped at %time% >> log.txt
The command ran, didn't do what I wanted it to, but still told me it did based on the way I wrote the script. Just something to watch out for....All things are possible, only believe.