Calling one Batch File from another (cascading batch files)

When you use batch files in windows xp, you may want to call a set of batch files from another batch file. Let’s say your file is named foo.bat and looks like this:

echo off
echo "Starting foo.bat"
subFoo1.bat
subFoo2.bat
echo "Finished foo.bat"

You will never see Finished foo.bat, since the batch processing will stop after the execution foo1.bat.

To fix this, you need to call the command line processor for each batch file:

echo off
echo "Starting foo.bat"
cmd /C subFoo1.bat
cmd /C subFoo2.bat
echo "Finished foo.bat"

Or you can use the call-command:

echo off
echo "Starting foo.bat"
call subFoo1.bat
call subFoo2.bat
echo "Finished foo.bat"

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.