1.

Solve : a main batch file (see below) that will call and run 6 other batch files?

Answer»

My PC: Window XP pro. with SP2

I am new to the Batch script. I have a main batch file (see below) that will call and run 6 other batch files for the nightly builds.

Right now, if the 1st batch file has the build error, it will hang on there, so other 5 batch files aren’t getting called at all.

Is there a way that the main batch file can continue call and run other batch files even if the 1st batch file - BW1_nightly_IS12.bat has not exited successfully?

Is there a way that I can get some sort of a message about the build errors for the BW1_nightly_IS12.bat?

Any input would be appreciated.

Thanks,
Betty
REM call multiple batch files to run the nightly release and debug version of the BW application

if exist "C:\batchFiles\nightluBuild_TIMESTAMP.TXT" del /Q "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"

Now.exe START! >> "C:\work\batchFiles\nightluBuild_TIMESTAMP.TXT"

Now.exe Running BW1 nightly build - release version - from trunk >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
call "C:\batchFiles\BW1\BW1_nightly_IS12.bat" > "C:\batchFiles\BW1\BW1_nightly_IS12_buildLog.txt"

Now.exe running the BW1 nightly build - from C:\BW1_ORC Branch >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
call "C:\batchFiles\BW1\BW1_ORC_nightly.bat" > "C:\batchFiles\BW1\BW1_ORC_nightly_buildLog.txt"

Now.exe running the BW1 FIRMWARE build - from trunk >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
call "C:\batchFiles\BW1\BW1_Firmware.bat" > "C:\batchFiles\BW1\BW1_Firmware_buildLog.txt"

Now.exe running the BW1 FIRMWARE build - from BW1_ORC branch >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
call "C:\batchFiles\BW1\BW1_ORC_Firmware.bat" > "C:\batchFiles\BW1\BW1_ORC_Firmware_buildLog.txt"

Now.exe Running BW1 nightly build - debug version - trunk >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
call "C:\batchFiles\BW1\BW1_nightly_DEBUG_IS12.bat" > "C:\batchFiles\BW1\BW1_nightly_DEBUG_IS12_buildLog.txt"

Now.exe Running BW1 nightly build - debug version - ORC branch >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
call "C:\batchFiles\BW1\BW1_nightly_debug_ORC_IS12.bat" > "C:\batchFiles\BW1\BW1_nightly_debug_ORC_IS12_buildLog.txt"

Now.exe BUILD DONE! >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"


I am thinking about to use the following line, and not sure if it’s a right way to do it.
IF ERRORLEVEL ==1 GOTO label nightlyBuild2


we test for ERRORLEVEL thus

IF ERRORLEVEL 1 GOTO nightlyBuild2

no equals signs, no word "label"

label looks like this

:nightlyBuild2


Why don't you ask the person who wrote the batch files?



Hello Contrex,

Thank you very much for your help. I am the person who wrote the batch file SINCE I am pretty new to the batch script, and I really don't know how to do a lot of thing yet at this moment.

Here is the updated main batch file, please have a look and let me know what you think.
One simple question, if the ERRORLEVEL is 0, what will happen to all labels?

Thanks a lot in advance,

Betty

REM call multiple batch files to run the nightly release and debug version of the BW application

if exist "C:\batchFiles\nightluBuild_TIMESTAMP.TXT" del /Q "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"

Now.exe START! >> "C:\work\batchFiles\nightluBuild_TIMESTAMP.TXT"

Now.exe Running BW1 nightly build - release version - from trunk >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
call "C:\batchFiles\BW1\BW1_nightly_IS12.bat" > "C:\batchFiles\BW1\BW1_nightly_IS12_buildLog.txt"
if errorlevel 1 goto notify1
:notify1
Now.exe BW1 nightly build - release version - from trunk exited with an errorlevel of 1! >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
goto nightlyBuild2

:nightlyBuild2
Now.exe running the BW1 nightly build - from C:\BW1_ORC Branch >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
call "C:\batchFiles\BW1\BW1_ORC_nightly.bat" > "C:\batchFiles\BW1\BW1_ORC_nightly_buildLog.txt"
if errorlevel 1 goto notify2
:notify2
Now.exe BW1 nightly build - from C:\BW1_ORC Branch exited with an errorlevel of 1! >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
goto nightlyBuild3

:nightlyBuild3
Now.exe running the BW1 FIRMWARE build - from trunk >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
call "C:\batchFiles\BW1\BW1_Firmware.bat" > "C:\batchFiles\BW1\BW1_Firmware_buildLog.txt"
if errorlevel 1 goto notify3
:notify3
Now.exe BW1 FIRMWARE build - from trunk exited with an errorlevel of 1! >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
goto nightlyBuild4

:nightlyBuild4
Now.exe running the BW1 FIRMWARE build - from BW1_ORC branch >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
call "C:\batchFiles\BW1\BW1_ORC_Firmware.bat" > "C:\batchFiles\BW1\BW1_ORC_Firmware_buildLog.txt"
if errorlevel 1 goto notify4
:notify4
Now.exe BW1 FIRMWARE build - from BW1_ORC branch exited with an errorlevel of 1! >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
goto nightlyBuild5

:nightlyBuild5
Now.exe Running BW1 nightly build - debug version - trunk >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
call "C:\batchFiles\BW1\BW1_nightly_DEBUG_IS12.bat" > "C:\batchFiles\BW1\BW1_nightly_DEBUG_IS12_buildLog.txt"
if errorlevel 1 goto notify5
:notify5
Now.exe BW1 nightly build - debug version exited with an errorlevel of 1! >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
goto nightlyBuild6

:nightlyBuild6
Now.exe Running BW1 nightly build - debug version - ORC branch >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
call "C:\batchFiles\BW1\BW1_nightly_debug_ORC_IS12.bat" > "C:\batchFiles\BW1\BW1_nightly_debug_ORC_IS12_buildLog.txt"
if errorlevel 1 goto notify6
:notify6
Now.exe BW1 nightly build - debug version - ORC branch exited with an errorlevel of 1! >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
goto end

Now.exe BUILD DONE! >> "C:\batchFiles\nightluBuild_TIMESTAMP.TXT"
:end;
Quote from: betty1 on October 08, 2007, 02:31:24 PM

One simple question, if the ERRORLEVEL is 0, what will happen to all labels?

Answer: you need to rewrite that batch!

It is my bed time here in England, I will look at this tomorrow but I will say a small thing about errorlevel

Errorlevel can be between 255 and 1 for errors and 0 for success. It returns TRUE if the return code was equal to or higher than the specified errorlevel. This means most of the time we only need to check IF ERRORLEVEL 1 ... and this will return TRUE for every non-zero return code.

Consider this code

myprogram.exe
IF ERRORLEVEL 1 goto bad
echo myprogram.exe was successful!
goto end
:bad
echo there was an error in myprogram.exe!
:end
echo end of batch

If myprogram.exe returned an errorlevel of 1 (or more!) then the IF is satisfied and the batch interpreter (cmd.exe) jumps to the label.
If myprogram.exe returned an errorlevel of 0 then the IF is NOT satisfied and the interpreter goes to the next line.

Your code

Quote
call "C:\batchFiles\BW1\BW1_nightly_IS12.bat" > "C:\batchFiles\BW1\BW1_nightly_IS12_buildLog.txt"
if errorlevel 1 goto notify1
:notify1

It will go to notify1 whether the errorlevel is 0 or >=1 (it is going there anyway!)



thanks for your speedy reply. Am I on the right track?

thank you very much,
Betty



call nightlyBuild1.bat
IF ERRORLEVEL 1 goto bad1
echo nightlyBuild1.bat was successful!
goto nightlyBuild2

:nightlyBuild2
call nightlyBuild2.bat
IF ERRORLEVEL 1 goto bad2
echo nightlyBuild2.bat was successful!
goto nightlyBuild3

:nightlyBuild3
call nightlyBuild3.bat
IF ERRORLEVEL 1 goto bad3
echo nightlyBuild3.bat was successful!
goto end

:bad1
echo there was an error in nightlyBuild.bat!
goto nightlyBuild2

:bad2
echo there was an error in nightlyBuild2.bat!
goto nightlyBuild3

:bad3
echo there was an error in nightlyBuild3.bat!
goto end

:end
echo end of batch
Quote from: betty1 on October 08, 2007, 04:29:56 PM
thanks for your speedy reply. Am I on the right track?

Yes, you are! Well done!

I think you missed a 1 here...

Quote
:bad1
echo there was an error in nightlyBuild.bat!
goto nightlyBuild2

also you don't need the lines in red (they are redundant)

Quote
call nightlyBuild1.bat
IF ERRORLEVEL 1 goto bad1
echo nightlyBuild1.bat was successful!
goto nightlyBuild2

:nightlyBuild2
call nightlyBuild2.bat
IF ERRORLEVEL 1 goto bad2
echo nightlyBuild2.bat was successful!
goto nightlyBuild3

:nightlyBuild3
call nightlyBuild3.bat
IF ERRORLEVEL 1 goto bad3
echo nightlyBuild3.bat was successful!
goto end


thanks a looooooooooooooot for all your help.

Since I want the main batch file continue call and run other batch files even if the nightlyBuild1 has not exited successfully. I thought IF nightlyBuild1 retuned an errorlevel of 0 then the nightlyBuild2.bat will be skipped, that’s why I added the redundant line in my script to call the label “:nightlyBuild2”.

After I re-read your message again, I thought that I misunderstood the IF and errorlevel concepts. In fact, IF nightlyBuild1 retuned an errorlevel of 0 then the IF statement will return false, and then the program will go to the next line. Am I right?

Thanks,
Betty
Quote from: betty1 on October 09, 2007, 09:45:45 AM
In fact, IF nightlyBuild1 retuned an errorlevel of 0 then the IF statement will return false, and then the program will go to the next line. Am I right?

Hi Betty

Yes, you are absolutely correct. If the IF test returns a 0 value, no diversion of normal program flow will happen.

For a mental exercise, you could try imagine what the code will look like if you tested for errorlevel 0 INSTEAD of 1.

An unconnected note about ERRORLEVEL (since you sound nice!)

Some programs are capable of returning multiple errorlevels. Since IF errorlevel N will return TRUE for any errorlevel equal to or greater than N, to get the right one, it is necessary to test in descending order. For example suppose you had a program that had 5 possible errorlevels

LaunchSpaceship.exe
IF errorlevel 5 goto alien-attack
IF errorlevel 4 goto out-of-fuel
IF errorlevel 3 goto pilot-is-drunk
IF errorlevel 2 goto pilot-is-tired
IF errorlevel 1 goto ships-cat-is-hungry

echo SUCCESSFUL LAUNCH
goto next

:alien-attack
(etc)

:next





Hello Contrex,

Thank you very much for PROVIDING me this very interesting example. I feel I have learned a lot from you today and yesterday. So, I'm really grateful for that.

Have a nice day,
Betty


Discussion

No Comment Found