Something is stumping me and I believe it's rather simple.
I have a batch script that executes two child scripts. Each child script are existed with EXIT / B 0 or EXIST /B 1 depending return codes of the operation they perform.
The children scripts are as follows:
Code: Select all
CALL PEMCOA7_FCSTSEQ_EMP.cmd PEMCOA7 Employee PEMFIN_FCSTSEQ_EMP.mxl
CALL PEMCOA7_FCSTSEQ_ADMIN.cmd PEMCOA7 Admin PEMFIN_FCSTSEQ_ADMIN.mxl
Then, then process returns to the parent script where it performs a TYPE invoking a function (CALL :MERGE_MAXL)
Everything up to here works perfectly fine.
However, after the function completes, the script does not spool the remaining redirections to the log file.
Here is my script:
Code: Select all
@ECHO OFF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::-- Script Name: PEMFIN_FCSTSEQ.cmd
::--
::-- Description: Used for the Generic Job Application
:: Executes PEMFIN_FCSTSEQ.cmd on the Essbase Server
::
::--
::-- Parameters: Call ENV.cmd to get environment variables to determine
:: login info, database, application, etc.
::--
::-- Author:
::-- Date:
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::-- Set working directory as script path --::
cd /d %~dp0
::-- Set Environment File --::
CALL _env.cmd
::-- Set Path Variables --::
SET GJALOGPATH=%1
SET GJAERRORPATH=%2
SET intrapath=%MAINPATH%%LOGPATH%%GJALOGPATH%
SET errorintrapath=%MAINPATH%%ERRORPATH%%GJAERRORPATH%
FOR /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set timestamp=%%a%%b)
FOR /f "tokens=* delims= " %%c in ("%timestamp%") do (set timestamp=%%c)
::-- Set Log and Error Files --::
SET logfile=%intrapath%%date:~-4,4%%date:~-10,2%%date:~-7,2%_%~n0.log
SET errorfile=%errorintrapath%%date:~-4,4%%date:~-10,2%%date:~-7,2%_%~n0.log
::-- Prepare Log and Error File Directories --::
FOR %%f IN ( %MAINPATH%%LOGPATH%%GJALOGPATH%* ) DO ( DEL %%f )
FOR %%f IN ( %MAINPATH%%ERRORPATH%%GJAERRORPATH%* ) DO ( DEL %%f )
echo ********************************************************>>%logfile%
echo Begin %~n0 Process at %TIME% >>%logfile%
echo ********************************************************>>%logfile%
CALL PEMCOA7_FCSTSEQ_EMP.cmd PEMCOA7 Employee PEMFIN_FCSTSEQ_EMP.mxl
CALL PEMCOA7_FCSTSEQ_ADMIN.cmd PEMCOA7 Admin PEMFIN_FCSTSEQ_ADMIN.mxl
SET myError2=%errorlevel%
IF %myError2%==0 goto MAXLF
echo ********************************************************>>%logfile%
echo Error Encountered in Begin %~n0 Process >>%logfile%
echo ********************************************************>>%logfile%
goto AbnormalExit
:MAXLF
echo ********************************************************>nul
echo Merge MaxL Standard Output into %~n0 >nul
echo ********************************************************>nul
::-- Merge MaxL Outputs into parent script --::
::-- Ability to differentiate between PEMFIN and PEMCOA7 --::
::-- Merges process MaxL based on like characters --::
SET "WCS1=*PEMCOA7_FCSTSEQ_*_MaxL.log"
SET "WCS2=*PEMFIN_FCSTSEQ_*_MaxL.log"
SET "WCS3=PEMFIN_FCSTSEQ.log"
CALL :MERGE_MAXL %WCS1% %WCS2% %WCS3%
:NormalExit
echo ********************************************************>>%logfile%
echo %~n0 - Completed Successfully >>%logfile%
echo ********************************************************>>%logfile%
echo ********************************************************>>%logfile%
echo Normal Exit - %~nx0 >>%logfile%
echo ********************************************************>>%logfile%
date /t >>%logfile%
time /t >>%logfile%
::-- Archive Log Files --::
FOR %%f IN (%MAINPATH%%LOGPATH%%GJALOGPATH%*) DO (
IF NOT EXIST "%MAINPATH%%LOGPATH%%GJALOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%" (
MKDIR "%MAINPATH%%LOGPATH%%GJALOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
)
COPY /Y %%f "%MAINPATH%%LOGPATH%%GJALOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%\%%~nf_%timestamp%%%~xf"
)
EXIT /B 0
:AbnormalExit
echo ********************************************************>>%errorfile%
echo %~n0 results in Abnormal Exit >>%errorfile%
echo ********************************************************>>%errorfile%
echo Please Check the log file for errors >>%errorfile%
echo ********************************************************>>%errorfile%
echo Abnormal Exit - %~nx0 >>%errorfile%
echo ********************************************************>>%errorfile%
date /t >>%errorfile%
time /t >>%errorfile%
::-- Archive Error Files --::
FOR %%f IN (%MAINPATH%%ERRORPATH%%GJAERRORPATH%*) DO (
IF NOT EXIST "%MAINPATH%%ERRORPATH%%GJAERRORPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%" (
MKDIR "%MAINPATH%%ERRORPATH%%GJAERRORPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
)
COPY /Y %%f "%MAINPATH%%ERRORPATH%%GJAERRORPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%\%%~nf_%timestamp%%%~xf"
)
EXIT /B 1
:::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::: Funtions Below Here ::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::
:MERGE_MAXL
PING -n 2 127.0.0.1>nul
IF EXIST "%MAINPATH%%LOGPATH%%GJALOGPATH%%1" (
PUSHD %MAINPATH%%LOGPATH%%GJALOGPATH%
FOR /R %%A in ( %1 ) DO (
TYPE "%%A"
)>>%date:~-4,4%%date:~-10,2%%date:~-7,2%_%3
POPD
)
PUSHD %MAINPATH%%LOGPATH%%GJALOGPATH%
FOR /R %%A in ( %2 ) DO (
TYPE "%%A"
)>>%date:~-4,4%%date:~-10,2%%date:~-7,2%_%3
POPD
PING -n 2 127.0.0.1>nul
GOTO :EOF
The portion of code that's not getting redirected to the log file is the portion following the Function:
Code: Select all
echo ********************************************************>>%logfile%
echo %~n0 - Completed Successfully >>%logfile%
echo ********************************************************>>%logfile%
echo ********************************************************>>%logfile%
echo Normal Exit - %~nx0 >>%logfile%
echo ********************************************************>>%logfile%
date /t >>%logfile%
time /t >>%logfile%
Is there anything you see in my script that prevents that portion from being written to my log file?