Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a batch file which calls another batch file that exists in PATH directory (basically calling an executable with additional switches.)

: bar.bat:
foo.bat file1.txt
foo.bat file2.txt

In foo.bat:

foo.exe -t -s %1

bar.bat executes the first command but exits immidately (i.e. working on file1.txt only).

How can I make this batch file to invoke the other batch file more than once?

share|improve this question
up vote 13 down vote accepted

Use the CALL keyword:

call foo.bat file1.txt
call foo.bat file2.txt
share|improve this answer
<copied from Duncan Smart's answer, just to keep it together> In addition to @splattne's answer, use exit /b in the CALLed batch file if you need to return early. – Brad Bruce May 26 '09 at 11:33
You can also use goto :eof to return early. exit /b is usually only needed if you need the return code. – Joey Jan 11 '10 at 9:21
I don't why but I am struggling to get this to work, I have tried both exit /b and goto: eof. Is it ok to be appending the output of the CALLed bat? call foo.bat > myfile – SSH This Oct 26 '12 at 21:39

In addition to @splattne's answer, use exit /b in the CALLed batch file if you need to return early.

share|improve this answer

Another option (for compatibility with DOS prior to version 3.3 :-) ) is to call the command process with the child (/c) option and the name of the other batch file to process. That will also do a call instead of a chain, and will even work on truly ancient machines (just in case someone runs across this and cares). :-)

share|improve this answer

@echo off

echo WbLegalReport.cmd


cd I:\CFS\Batch\jarDir

echo %CD%


echo %CD%

echo WatchResrAddDeleted.cmd

echo %CD%


echo %CD%

What I am trying to do here is call these two batch files in a sequence.

Unable to do so.

help please.

Acutally it is failing at the child script, As the control does not return back to the main script

share|improve this answer

Sanket, don't call the batch file directly. Use the "CALL" command. See splattne's example.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.