I have written a DOS batch file that will create backups of my SQL Server databases and save them off into appropriate directories. If the backup works correctly, then the next process should be kicked off.
After playing around some, I was able to create an iDM procedure that called the batch file. The procedure is pretty simple. It only has the following two lines...
-SET &BACKUP='"' | &&ENV_DATA || '\SCRIPTS\backup_databases.bat"';
The ENV_DATA is a variable that is set in the edasprof file. In our test environment, the variable is then overridden in the user profile so that each developer can have their own environment setup.
Anyway, this seems to work fine. I had some issues at first getting the batch file to work correctly when it was called from iDM (had to do with the path). Now, I want to be able to capture the return code and use it. If the backup was successful, then the next process should be called. If it wasn't successful, then don't call it (well, probably call an error routine instead).
How do I capture the return code from the DOS batch file that I called?
ThanksThis message has been edited. Last edited by: <Kathryn Henning>,
Windows, All Outputs
Try using &RETCODE.
Someone else pointed me towards using SYSTEM. That is what you need if you want to be able to capture the return code. However, I am still having issues. I am able to call the DOS batch script, but it always seems to give me a return code of 0. So, I wrote the following simple iDM procedure and DOS batch files...
The iDM procedure is...
-SET &RETCODE = SYSTEM(25,'e:\SCRIPTS\test.bat AFTER','D4');
-TYPE #### Return Code: &RETCODE
The batch file being called (which is on the DM server) is...
ECHO Starting batch file
if (%1)==(BEFORE) EXIT /B 1
if (%1)==(AFTER) EXIT /B 2
ECHO No parameters
EXIT /B 0
Since the batch file is being passed AFTER as a parameter, I am expecting (hoping) to see a return code of 2. I keep seeing a return code of 0. I have tried it with and without the /B parameter on the exit statement in the DOS batch file. The batch file seems to be taking the correct path. The output shows that it is exiting because the parameter was AFTER. Here is the console log...
02/12/2014 14:14:21 DANL-DEV C:\ibi\srv77\dm\edatemp\ts000011>ECHO Starting batch file
02/12/2014 14:14:21 DANL-DEV Starting batch file
02/12/2014 14:14:21 DANL-DEV C:\ibi\srv77\dm\edatemp\ts000011>if (AFTER) == (BEFORE) EXIT /B 1
02/12/2014 14:14:21 DANL-DEV C:\ibi\srv77\dm\edatemp\ts000011>if (AFTER) == (AFTER) EXIT /B 2
02/12/2014 14:14:21 DANL-DEV #### Return Code: 0
Anyone have any ideas on why I am not seeing the number that is being set in the EXIT?
Windows, All Outputs
|Powered by Social Strata|