Page 1 of 1
Dos Batch: Kill parallel jobs at the same time
Posted: 16 Nov 2010 01:06
by prem
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.
Re: Dos Batch: Kill parallel jobs at the same time
Posted: 16 Nov 2010 02:23
by amel27
Each (parallel) bat job run in its own process (CMD.EXE) and its own window, so you must ended each BAT separately (Ctrl+C)... Nevertheless, child BAT jobs can check if main job exists, and ended if not - by (unique) existing job window title or process name, see this thread for sample:
viewtopic.php?f=3&t=1386
Re: Dos Batch: Kill parallel jobs at the same time
Posted: 18 Nov 2010 06:03
by prem
Thankyou..Is there any way I can come out of this by one ctrl+C
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