Check output of called Script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ace_Friends22
Posts: 2
Joined: 27 May 2021 04:15

Check output of called Script

#1 Post by ace_Friends22 » 27 May 2021 04:28

Hi All,

We have a batch script, which executes Informatica jobs. This is an existing batch script called "Master_Batch.bat"

I am writing a new batch script, which call above script in loop (for example, call 5 times).

Now the problem is, it runs the master_batch.bat only once and exit the process. When I remove master_batch.bat call from the new script, I can see it iterates 5 times.

Can someone please help how to debug this? I cannot make any change in "Master_Batch.bat" as it is working in production correctly. I just wanted to check why it gets exit after 1st run. With my analysis, the Master_Batch.bat is completing successfully.

Below is code from my new batch script.

Code: Select all

@ECHO OFF
set loopcount=1
:loop
echo %loopcount% >> test.log
Master_Batch.bat DWSE CUSTOMER_DEMAND_FILL
set /a loopcount=loopcount+1
if %loopcount% ==6 exitloop
goto loop
:exitloop
Without Master_Batch.bat call, log fle shows 1 2 3 4 5
With Master_Batch.bat call, log file shows only 1

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Check output of called Script

#2 Post by penpen » 27 May 2021 19:49

At the moment you don't call another batch file.
You just tell the command line processor to execute a different batch file (with new parameters) instead of the actual one.
It's like changing the disc in your DVD-Player - there can be only one.
Previously processed batch files and progress in them are forgotten.

If you want to execute a child batch from an specific batch and want to return the control to that batch file, once the child finishes, then you should call the child by using the "call"-command:

Code: Select all

call Master_Batch.bat DWSE CUSTOMER_DEMAND_FILL

penpen

ace_Friends22
Posts: 2
Joined: 27 May 2021 04:15

Re: Check output of called Script

#3 Post by ace_Friends22 » 01 Jun 2021 06:02

Hi PenPen,

I tried calling with CALL function, but inner BATCH script contains GOTO statement and I believe that's the reason it is not returning back.

To cross validate it,

From original Master_Batch.bat script, I removed/modified logic with GOTO function and used that script. It is working as expected with/without CALL. But the moment I use Master_Batch.bat, it is running only once.

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Check output of called Script

#4 Post by penpen » 01 Jun 2021 18:36

I'm not sure i fully understand you:
Except for exceptions that are able to completely abort batch file execution
and the start-command used with specific arguments, that might open a new window, which might not be closed,
nearly whatever programming logic you use in "Master_Batch.bat" shouldnt affect your new batch file.
Given that you don't seem to use "setlocal" and "endlocal" in your new batch (or at least that code you gave),
the "Master_Batch.bat" might have overwritten the "loopcount"-variable to the value 6.

However, if the "Master_Batch.bat" properly uses "setlocal" and "endlocal" statements, the following should work:

Code: Select all

@ECHO OFF
set loopcount=1
:loop
echo %loopcount% >> test.log
call Master_Batch.bat DWSE CUSTOMER_DEMAND_FILL
set /a loopcount=loopcount+1
if %loopcount% ==6 exitloop
goto loop
:exitloop

penpen

Post Reply