Solved

Batch Job - Call one after another

Posted on 2013-01-01
5
874 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
5 Comments
 
LVL 51

Assisted Solution

by:Bill Prew
Bill Prew earned 100 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 400 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 24

Expert Comment

by:lionelmm
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

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

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…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

18 Experts available now in Live!

Get 1:1 Help Now