Dos Batch: Kill parallel jobs at the same time

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
prem
Posts: 4
Joined: 15 Nov 2010 23:44

Dos Batch: Kill parallel jobs at the same time

#1 Post by prem » 16 Nov 2010 01:06

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.

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: Dos Batch: Kill parallel jobs at the same time

#2 Post by amel27 » 16 Nov 2010 02:23

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

prem
Posts: 4
Joined: 15 Nov 2010 23:44

Re: Dos Batch: Kill parallel jobs at the same time

#3 Post by prem » 18 Nov 2010 06:03

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

Post Reply