1.

Solve : Dos Batch: Kill parallel jobs at the same time?

Answer»

I am running the bat job(main bat) and that will call the two bats parallely at the same time,

I have tried to end the job(main bat) by ctrl+c then one bat file is getting ended, but the other bat file is still running,so again I have to do the ctrl+c to end the other bat file.

So how can I kill all the bat files at the same time and also how can i program this in the main bat job so that all the parallel jobs gets ended when I use ctrl+c.



Can some body please help me on this.



Thanks in advance. Quote

I am running the bat job(main bat) and that will call the two bats parallely at the same time,

How are you doing that? When a call is made, the calling file enters a wait state and the called file begins executing. When the called file ends, control is returned to the calling file at the next sequential instruction after the call. This occurs no matter how MANY levels of calls are used. USING ctl+C will terminate the entire run unit.

It would be helpful if you posted your code and please mention your OS.

 Thankyou..

Following is the code of the main bat file..

D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MAbatch\jobs\old_Campaign_DB_Personal.bat
call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MAbatch\jobs\Count_db_pers.bat

Following is the code for the 2 bat files..

Following is the code of the first bat file...

setlocal
REM *********************************************************
REM * Rundate 'D'YYMMDD must be specified as first argument *
REM *********************************************************

REM *********************************************************
REM * Command-file must exist *
REM *********************************************************
FOR /R D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\ %%G IN (*.bat) DO start /b "call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\" %%G


set rc=%errorlevel%
REM *******************************************************
REM * Exit script and report return code *
REM *******************************************************
:done
echo rc=%rc%
exit /b %rc%

REM *******************************************************
REM * Handle argument errors *
REM *******************************************************
:noargument
echo Error: No argument specified
set rc=2
goto done
:nopgm
echo Error: Command file "%sch_command%" does not exist
set rc=2
goto done

Following is the code of the second bat file.

echo off & setLocal enableDELAYedexpansion
set toterrors=
set totjobs=
for /f "tokens=1 delims= " %%a in (D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\count\count.txt) do (
set /a toterrors+=%%a
)
for /f "tokens=2 delims= " %%b in (D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\count\count.txt) do (
set /a totjobs+=%%b
)
echo total errors is !toterrors!
echo total jobs is !totjobs!
goto :EOF
Wow!

Main.bat
Quote
D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MAbatch\jobs\old_Campaign_DB_Personal.bat
call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MAbatch\jobs\Count_db_pers.bat

The first statement will transfer control to old_Campaign_DB_Personal.bat. There is no mechanism to return, the next statement (call) will never GET executed.

First.bat
Quote
FOR /R D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\ %%G IN (*.bat) DO start /b "call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\" %%G

Choose either start or call but not both. Note the /b switch on the start command disables CTL+C.

The Second.bat file seems OK.

It may help to map out what you expect to happen, read up on the both the start and call commands and go from there.

Good luck.


Discussion

No Comment Found