Jump to content

Recommended Posts

Posted

hi guys,

 

I want to know how can i run multiple scheduled tasks where one task depends on the outcome of a previous task. Could this be done using script?

 

thanks

Posted

In short, yes :-)

 

Longer answer really involves what are you doing in each task and how will you know that the previous stage has completed OK?

 

At the simplest level, lets say that you have 3 batch files called batch1.cmd, batch2.cmd and batch3.cmd and each of them will carry out some task and return an errorlevel of 0 if they work and none zero if they fail.

 

A single batch file containing:

 

batch1.cmd && batch2.cmd && batch3.cmd

 

Will run batch1 and, if it succeeds run batch2 and, if that succeeds will run batch3

 

if you haven't got nice tidy tasks like that to run (and if you can control the tasks to be run it's well worth making sure that they do return an errorlevel so you can do this sort of thing) then you need to have something which checks to see if the task has succeeded.

 

For example, you have a task which is going to create an icon on the "all users" desktop and, assuming that succeeds you want to do something else. That first task is called batch1.cmd, the next one is called batch2.cmd. Your controlling batchfile could then look something like this:

 

start /wait batch1.cmd
if not exist c:\users\public\desktop\newshortcut.lnk goto batch1_failed
start /wait batch2.cmd
goto end

:batch1_failed
echo Failed to run batch file 1

:end

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...