0

I'm trying to write a batch job that executes via task scheduler. The objective is to run these exe jobs sequentially. However, some of these jobs have dependencies on others. for eg.

  1. job1.exe (no dependencies. exe for an API call)
  2. job2.exe (no dependencies. exe for an API call)
  3. job3.exe (python file in exe, requires job1 to run successfully, waiting 3 mins before executing)
  4. job4.exe (python file in exe, requires both job2 and job1 to run successfully waiting 3 mins before executing)

Aim : to run job1 and job2 in parallel job3 and job4 whenever possible currently it's set up like this:

START /min "" "%~dp0\ job1.exe
IF %ErrorLevel% EQU 0 (
    TIMEOUT /t 180
    START /min "" "%~dp0\job3.exe) 
)ELSE (
    ECHO job3 did not run because job1 failed
TIMEOUT /t 180

START /min "" "%~dp0\ job2.exe
IF %ErrorLevel% EQU 0 (
    START /min "" "%~dp0\job4.exe) 
)ELSE (
    ECHO job4 did not run because job2 failed
TIMEOUT /t 180 

Currently, the jobs don't work.

  • Are the jobs failing when you run the batch file manually, or is the scheduled task failing to run? What error[s] are you getting? Do any of the processes require elevation, interaction, or start a windowed application? – SamErde Jun 30 '21 at 12:45
  • **1st** there are syntax errors (missing trailing double quotes). **2nd** Even if you fix those, e.g. `START /min "" "%~dp0job1.exe"` then `job1` should run in parallel (asynchronously). **3rd** You should initially [set `ErrorLevel` to 0](https://superuser.com/a/649329/376602) (read more about ErrorLevel at https://ss64.com/nt/start.html). – JosefZ Jun 30 '21 at 22:02

0 Answers0