.cmd file help

I need to create a .cmd file that executes two items...

First a .bat file and second a .exe file

The .bat file must complete successfully (return code zero) for the .exe to start.

I have close to no experience creating .cmd files or batch files. If anyone could help me out or point me in the right direction for a tutorial how to do this, that would be great. Thanks in advance. Sorry if this is the wrong forum, wasn't sure where to put it.
[474 byte] By [btisdabomb] at [2007-11-19 23:56:49]
# 1 Re: .cmd file help
No matter what you are trying to accomplish, that does not seem to be a good option.

What exactly is this batch file to do and when it executes the EXE, what is that EXE going to do?
PeejAvery at 2007-11-9 12:18:16 >
# 2 Re: .cmd file help
A .cmd file and a .bat file are the same thing, just named differently for the newer versions of Windows.

.cmd files execute a line at a time (async?), so just put the .bat file commands before the .exe, and they wll run first. (or at least that's been my experience)
dglienna at 2007-11-9 12:19:16 >
# 3 Re: .cmd file help
Right, but if the .bat command returns an error then I don't want to run the .exe

Here is what I have come up with... If you see something wrong with it let me know as I haven't ever created a .cmd file before.

REM *************** Execute PrepareTables_SnDataPersistor ***********************

Set ReturnCode=0

CALL dsp_Dist_PrepareTables.bat
Set ReturnCode=%ErrorLevel%

If %ReturnCode% == 0 GoTo SnDataPersistor
Set ReturnCode=99
Goto End

:SnDataPersistor
START SlnDataToCMGPersistor.exe

If %ReturnCode% == 0 GoTo End
Set ReturnCode=99
Goto End

:End

Exit
btisdabomb at 2007-11-9 12:20:14 >
# 4 Re: .cmd file help
If that works, then go with it. You didn't post that you needed the return code.
dglienna at 2007-11-9 12:21:19 >
# 5 Re: .cmd file help
I can't get this to work right...

I have modified my file to log what is happening.
Here is what I have

REM *************** SalesNEtDRPersistor.cmd ***********************

Set ReturnCode=0

REM ********* change the following Drive= to reference a log file from where the logfile should be written

Set Drive=d:\apps\SalesNet\SalesnetToCMG\CMGPersistor\Log\
Set Logfile=%Drive%SalesNetDRPersistor.log

echo *************** SalesNetDRPersistor.cmd *********************** > %logfile%
echo **** Starting Date Time: ******** >> %logfile%
echo %Date% %Time% >> %logfile%
echo ********************************* >> %logfile%


CALL D:\apps\SalesNet\SalesnetToCMG\CMGPersistor\dsp_Dist_PrepareTables.bat
echo *************** .bat ErrorLevel *********************** > %logfile%
Set ErrorLevel=%ReturnCode%

echo %ErrorLevel%

If %ReturnCode%==0 Goto SnDP
Set ReturnCode=99
Goto End

:SnDP
echo *************** Starting SlnDataToCMGPersistor.exe *********************** > %logfile%
echo **** Starting Date Time: ******** >> %logfile%
echo %Date% %Time% >> %logfile%
echo ********************************* >> %logfile%
CALL D:\apps\SalesNet\SalesnetToCMG\CMGPersistor\SlnDataToCMGPersistor.exe

If %ReturnCode%==0 Goto End
echo *************** ERROR *********************** > %logfile%
echo **** Ending Date Time: ******** >> %logfile%
echo %Date% %Time% >> %logfile%
echo ********************************* >> %logfile%
Set ReturnCode=99
Goto End

:End
echo *************** FinishTime *********************** > %logfile%
echo **** Ending Date Time: ******** >> %logfile%
echo %Date% %Time% >> %logfile%
echo ********************************* >> %logfile%

Exit

After it calls D:\apps\SalesNet\SalesnetToCMG\CMGPersistor\dsp_Dist_PrepareTables.bat, it stops. The log from dsp_Dits...bat shows that it is executing and has a ReturnCode of 0

Any ideas why it stops after that?
btisdabomb at 2007-11-9 12:22:18 >
# 6 Re: .cmd file help
No, but it may be running too quickly? Can you try using

Start /Wait

instead of

Call

to see if that matters?
dglienna at 2007-11-9 12:23:16 >
# 7 Re: .cmd file help
[ merged ]

Regards,
Siddhartha
Siddhartha at 2007-11-9 12:24:20 >