waiting for previous command to finish before executing next

D

djc

using sc.exe (manages services) as an example, when issuing several
commands one after another will the first finish before going on to the next
command? for example:

sc \\computername stop servicename
sc \\computername start servicename

1) will the service finish stopping before the next line issues the start
command in this case?
2) is it the default behavior of batch files to finish one command
completely before going to the next? or does it depend on the command?
3) If the answer is that each command completes before going on to the next,
which I think it is but I am looking for verification, is there a way to
change that? for example lets say each line of a batch file kicks of a file
copy process and you don't want to wait for each on to finish before going
on to the next one... how would you arrange that?

Thanks in advance... any info is greatly appreciated.
 
M

Mark V

In said:
using sc.exe (manages services) as an example, when issuing
several commands one after another will the first finish before
going on to the next command? for example:

sc \\computername stop servicename
sc \\computername start servicename

1) will the service finish stopping before the next line issues
the start command in this case?

The SC.EXE process itself will return before batch processing
continues to the next line. As to whether the STOP (or start or
pause or continue) command succeeds is a different question.

An additional issue for Service Control operation is that SC might
return before the SCM actually completes the operation. The usual
fix for this is to insert a wait into the batch between the commands.
Often: ping -n 6 127.0.0.1 >nul
or similar.
2) is it the default behavior of batch files to finish one command
completely before going to the next? or does it depend on the
Yes.

command? 3) If the answer is that each command completes before
going on to the next, which I think it is but I am looking for
verification, is there a way to change that? for example lets say
each line of a batch file kicks of a file copy process and you
don't want to wait for each on to finish before going on to the
next one... how would you arrange that?

use the START command. START /?
...
START "" "<path>\sc" \\computername stop servicename
START "" "<path>\sc" \\computername stop servicename2
START "" "<path>\sc" \\computername stop servicename3
...

But once you start something in a new window, usually the parent
process (the batch) can no longer know as much about the child
proccess.

Note that many Win32 GUI programs run from then commandline return
control to CMD immediately and do not cause batch processing to wait.
That is usually the case too when an associated document is "run"
from cmd.
 
D

djc

great! thanks for all the info!

Mark V said:
The SC.EXE process itself will return before batch processing
continues to the next line. As to whether the STOP (or start or
pause or continue) command succeeds is a different question.

An additional issue for Service Control operation is that SC might
return before the SCM actually completes the operation. The usual
fix for this is to insert a wait into the batch between the commands.
Often: ping -n 6 127.0.0.1 >nul
or similar.


use the START command. START /?
...
START "" "<path>\sc" \\computername stop servicename
START "" "<path>\sc" \\computername stop servicename2
START "" "<path>\sc" \\computername stop servicename3
...

But once you start something in a new window, usually the parent
process (the batch) can no longer know as much about the child
proccess.

Note that many Win32 GUI programs run from then commandline return
control to CMD immediately and do not cause batch processing to wait.
That is usually the case too when an associated document is "run"
from cmd.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top