I have a .bat file to which I can pass parameters.
LOAD_TABLE_WRAPPER.BAT Table1 DEV
Briefly, it runs an SQL to load Table1 on the Dev environment. Now, I want it to load multiple tables overnight. So, I set up a master .BAT which goes something like
::MASTER_LOAD.BAT
CALL LOAD_TABLE_WRAPPER.BAT Table1 Dev
CALL LOAD_TABLE_WRAPPER.BAT Table2 Dev
CALL LOAD_TABLE_WRAPPER.BAT Table3 Dev
If I submit MASTER_LOAD.BAT from cmd, it executes the load for Table1 but does not proceed to Table2 load. These are the last two lines of the WRAPPER.BAT
:eof
exit %ERROR_STATUS%
To display the command prompt, type echo on. If used in a batch file, echo on and echo off don't affect the setting at the command prompt. To prevent echoing a particular command in a batch file, insert an @ sign in front of the command.
Your exit %error_status%
command in LOAD_TABLE_WRAPPER.BAT is terminating your batch session, so your MASTER_LOAD.BAT never gets a chance to resume with the next call.
You can fix the problem simply by adding the /B option to your EXIT command
exit /b %error_stats%
I almost never use EXIT without /B in a batch file (though there are times when /B is not wanted).
But another alternative is to run the called scripts via CMD instead of CALL.
::MASTER_LOAD.BAT
CMD /C LOAD_TABLE_WRAPPER.BAT Table1 Dev
CMD /C LOAD_TABLE_WRAPPER.BAT Table2 Dev
CMD /C LOAD_TABLE_WRAPPER.BAT Table3 Dev
There are a number of differences between the methods
CALL with EXIT /B
CMD /C
I would never recommend using CMD /C over CALL unless the called batch files have EXIT without the /B option and you cannot modify the batch file to add the /B option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With