Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMD - Wait for parallel command lines to finish?

I execute 4 tasks in parallel via command line ( win7 cmd):

start defrag /A c:
start defrag /A d:
start defrag /A e:
start  defrag /A f:
dir 

However the dir command execute right after the first line .

I want the dir command to execute after all 4 are done.

how can I do it ?

like image 669
Royi Namir Avatar asked Jul 25 '26 23:07

Royi Namir


2 Answers

Try this:

start defrag /A c:
start defrag /A d:
start defrag /A e:
start defrag /A f:

:StartLoop
:: Check whether any of the defrags are running...
tasklist|Findstr /i /c:"defrag"
:: Exiting the loop if tasklist didn't find any defrags.
If %errorlevel% NEQ 0 (
   GoTo :ExitLoop
)
choice /T 10 /D Y /M "Waiting for 10 seconds..."
GoTo :StartLoop
:ExitLoop
dir 
like image 105
Ciove Avatar answered Jul 27 '26 12:07

Ciove


This will cause defrag /A [drive] to run for c, d, e, and f, waiting for each to finish before starting the next. Finally, it will exit and run dir.

for %%i in (c d e f) do start "" /B /WAIT defrag /A %%i:

dir
like image 34
Daniel Avatar answered Jul 27 '26 11:07

Daniel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!