How to specified dependency in a .bat file

Posted on 2006-04-24
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
    LVL 95

    Accepted Solution

    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.
    LVL 7

    Assisted Solution

    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 95

    Expert Comment

    by:Lee W, MVP
    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.
    LVL 7

    Expert Comment

    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Organizations create, modify, and maintain huge amounts of data to help their businesses earn money and generally function.  Typically every network user within an organization has a bit of disk space to store in process items and personal files.   …
    Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now