# Unable to call multiple bat files from single bat file



## prem_arvapalli (Nov 15, 2010)

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_Personal.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?


----------



## Squashman (Apr 4, 2003)

The call to the 2nd Batch file will not execute until the first batch file is done executing and has exited.


----------



## prem_arvapalli (Nov 15, 2010)

Thankyou..

I dont know dos scripting, can you tell me where to change in the code to get the desired results.


----------



## Squashman (Apr 4, 2003)

Why don't you post the code for all your batch files here and maybe we can take a look at why they are not working they way you want them too.

If the 2nd one is not running then the first one is not done executing. So you will have to look at the first one and find out why it is not exiting so that the 2nd batch file can execute.


----------



## prem_arvapalli (Nov 15, 2010)

Thankyou..

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


----------

