0

I've a windows batch script calling another batch every 10 mins. I used a For loop to call the batch and then wait for 10 mins.


@ECHO OFF
echo %date:~0,10% %time% Running Post To GIM II ...
FOR %%a IN (1,2,3,4,5) DO (
echo %date:~0,10% %time% Starting Post To GIM II ...
CALL D:\Appshares\Autosys\scripts\Sophis\_commonJobWrapper.bat    D:\sophis\Client\UBS_PostToGIMII.exe
echo %date:~0,10% %time% Ending Post To GIM II ...
PING -n 600 127.0.0.1 >NUL 2>&1 
)

However the inner batch accepts another .exe as a parameter. But the inner batch executes only once and then exits. The inner batch code is like this. Can anybody tell why the loop is always exiting after 1 run?


@echo off

REM parameter 1 is the program to be called, parameter 2 onwards are additional optional parameters
REM -- Record Time
echo --- JobWrapper Start : %date% %time% ---

REM -- Set starting folder to where application was called from
  cd /d %~dp0
REM -- Set Secure varibales via a securly permissioned file
  if exist _CommonBeginSecure.BAT (call _CommonBeginSecure.BAT)
REM -- Debug mode, start message
  if "%_senddebug%" NEQ "" cscript.exe /NOLOGO %_sendmail% "%_applic% (%_envname%): Autosys job started - %~nx1" "Logfile: %~n1.out" %_senddebug% %_sendfrom%
REM -- Call program passing thru any parameters (currently maximum of 9)
  echo Calling: %1
  call %1 %2 %3 %4 %5 %6 %7 %8 %9
REM -- Error Handling
if %errorlevel% NEQ 0 goto error
goto end

:error

REM -- Send Failed Message
if "%_sendto%" NEQ "" cscript.exe /NOLOGO %_sendmail% "%_applic% (%_envname%): Autosys job FAILED - %~nx1" "Logfile: %~n1.out  (Errorlevel: %2)" %_sendto% %_sendfrom%
exit 1

:end
REM - Debug mode, end message
if "%_senddebug%" NEQ "" cscript.exe /NOLOGO %_sendmail% "%_applic% (%_envname%): Autosys job finished - %~nx1" "Logfile: %~n1.out" %_senddebug% %_sendfrom%
REM -- Record Time 
echo --- JobWrapper End : %date% %time% ---    
exit 0
rem - Notes:
rem %0 = Full name of this job 
rem %~dp0 = Actual path of this job
rem     %~nx0 = Filename of this job
rem     %~n0  = Filename of this job (excluding extension)

1 Answer 1

1

You need to use exit /b errorcode.

Exit command, without /b closes cmd instance. With /b closes the running batch file.

Sign up to request clarification or add additional context in comments.

3 Comments

as an alternative, you can start your 'inner batch' instead of calling it. - so if it fails, it will not influence your Loop-Batch
But then, if no /B is used a new window is created and output goes to it, and if /b is used and no window is created then there is no wait for the second batch to finalize. exit /b is simpler and involves less changes.
@mc_nd: you are definitly right - just a possible alternative :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.