Page 1 of 1

Unable to call multiple bat files from single bat file

Posted: 15 Nov 2010 23:48
by prem
I am trying to call the bat file(main.bat) which contains 2 bat files(first, second and first bat files internally calls multiple bat files and outputs that to a file(also echos) and second bat file reads that file and calculates the total and echos back to the dos
so when I execute the main bat file, it is executing the first bat file and giving the results, but the second bat file I dont see it is executing as it is not echoing any results.

Following is the code of the main bat file

D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MAbatch\jobs\old_Campaign_DB_Person al.bat --- first bat
call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MAbatch\jobs\Count_db_pers.bat----second bat

Can some body please help me on this?

Re: Unable to call multiple bat files from single bat file

Posted: 16 Nov 2010 02:30
by amel27
if you start separate BAT job you can use:

Code: Select all

start "Job 1" CMD /C "Job_1.bat"

if you start BAT within current job you must use CALL

Code: Select all

CALL "Include_1.bat"

Re: Unable to call multiple bat files from single bat file

Posted: 18 Nov 2010 05:56
by prem
Thankyou.. Can you tell me where exactly do I have to change in the code.. following is the code of the first and second bat file

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