How to specified dependency in a .bat file

Posted on 2006-04-24
Medium Priority
Last Modified: 2010-04-18

I want to create a batch file, which executes two commands. The second one can not be executed until the first is completed. How do I do that?

Thank you.
Question by:jyhuang
  • 2
  • 2
LVL 97

Accepted Solution

Lee W, MVP earned 252 total points
ID: 16527644
Place them sequentially.  Batch files do not proceed without completing the previous task.

For example,  create a batch file that starts notepad and calculator -


Then run it.  Note that when notepad starts, the "dos" window remains open with a flashing cursor.  When you close notepad, calc starts and the window will disappear - the batch file doesn't continue until the first program completes running.

Assisted Solution

Cherukuri30 earned 248 total points
ID: 16527646
by default the commands embedded in a batch file are executed in sequential order first is first and second is second.


you looking for a conditional execution meaning if first command is executed then only the second should be executed some thing like if condition?
LVL 97

Expert Comment

by:Lee W, MVP
ID: 16527653
Note, if your particular two programs don't function the same way in the batch file, the first program may do something differently, in which case there are several ways in which to keep the batch program from continuing until the first program is done.

Expert Comment

ID: 16527737
look at the below example if you are looking for conditional execution

if not exist myfile.txt goto MESSAGE
echo The file does not exists on the current directory
goto END

echo The file exists in the current directory.


in the above example i am trying to find a file called myfile.txt is existing in the current directory or not if it finds the file then execution goes to the the label MESSAGE and displays the message.

If file is not found then the line below if statement will be displayed and the control execution will goto end of the program

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question