|
Answer» I have 3 batch scripts. The first executes the second as part of a loop. The second executes the third as part of a loop also. The point is to spawn 4 separate threads that each loop over a few process input files running some PROCESSES on each input file.
1)
This starts the 4 threads. %1 is the total number of input files to be processed.
for /L %%A in (1,1,4) do ( start Starter.bat %%A %1 ping 127.0.0.1 -n 30 > nul )
2)
This is the code for starter.bat. It executes the desired processes LOOPING over up to %2 input files by 4s.
for /L %%A in (%1,4,%2) do ( L:\Byrge\PolyPaths\Sys_Interface\Start_Command\Calc_LL_CF.bat %%A start /B L:\Byrge\PolyPaths\Sys_Interface\Start_Command\DB2_Load.bat %%A ) exit
3)
This is the code within DB2_Load.bat. It is executed by starter.bat (#2 above) as its own Windows process. The echo hello line has been simplified.
echo Segment %1 runID prefix echo hello echo Finished loading segment %1 to Database exit
The exit in DB2_Load.bat (#3 above) works. The exit in Starter.bat (#2 above) does not.
Does anyone know why?
ThanksTry this modification to starter.bat:
for /L %%A in (%1,4,%2) do ( CALL L:\Byrge\PolyPaths\Sys_Interface\Start_Command\Calc_LL_CF.bat %%A start /B L:\Byrge\PolyPaths\Sys_Interface\Start_Command\DB2_Load.bat %%A ) exit
In a batch, if you just start a batch by name, control is transferred permanently to the second batch, and does not come back when the second batch exits. If you WANT to come back, use CALL.
Here is second.bat
@echo In second batch
Run this first batch and you won't see "Back again"
@echo off echo in first batch echo Starting second.bat second.bat echo Back again
Run this one and you will
@echo off echo In first batch echo Starting second.bat call second.bat echo Back again
Thanks. That worked perfectly.
|