?
Solved

Batch Job - Call one after another

Posted on 2013-01-01
5
Medium Priority
?
882 Views
Last Modified: 2013-01-04
Hello experts,

I have multiple batch jobs that I need to run in a sequence.  I don't know how long it will take each job to run, so I don't want to set a schedule.

I want to create 1 batch file that is schedule to run at 1am.  Is it possible to set this batch file to execute one batch job and then once complete, to start the other one?

Example:

Call Batch1.bat......
Complete....
Call Batch2.bat........
Complete
Call Batch3.bat
0
Comment
Question by:holemania
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 56

Assisted Solution

by:Bill Prew
Bill Prew earned 400 total points
ID: 38734845
Yes, and you actually are very close to the mechanics.  If you want to wait for each BAT to complete before the next starts then use CALL, as in this bat file example:

@echo off
call batch1.bat
call batch2.bat
call batch3.bat

~bp
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 1600 total points
ID: 38735131
Just to add... be careful you don't use the command "EXIT" to finish any of the batches otherwise it will stop the main one too.  Use EXIT /B to finish them instead or just let it work its way to the end of the batch file.  If one relies on the other at all you might want to set an error level and check for it, i.e.

@echo off
set error=NO
(call batch1.cmd || set error=Batch1 %errorlevel%
call batch2.cmd || set error=%error%Batch2 %errorlevel%
call batch3.cmd || set error=%error%Batch3 %errorlevel%
) > logfile.txt

if "%error%"=="NO" (
  echo Completed OK
  exit /b 0
) else (
  echo There was at least one error -- %error%
  exit /b 1
)

That would give you a logfile.txt of the output of the other batches and return errorlevel "1" to your scheduler if any of the other three had an error.

Lots of things you can do like emailing etc. but depends what you are scheduling and how important it is!

Steve
0
 
LVL 25

Expert Comment

by:Lionel MM
ID: 38736338
Steve is the master at batch files so if what you suggest works for you great. I deal with this by adding a line at the end of each batch file to start the next. That is to say at the end of batch1.bat and have a line to start batch2.bat, namely
Start batch2.bat; and then in batch2.bat I have the line Start batch3.bat; and then have my exit after the start batchx.bat to close the current one

@echo off
commands
commands
start batch2.bat
exit
0
 

Author Closing Comment

by:holemania
ID: 38744973
Thank you.  That worked wonderfully.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38745120
No problem... a little over complicating a three line batch but with the benefit of some error checking.

thanks

Steve
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

752 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