Sunday, 7 March 2010

Batch Job Scheduling

Q&A

When we receive multiple requests from customers, in a short period of time, asking for a solution to the same issue, it is time to write a blogpost about it.

Automatically Run New Bat or CMD files

The question asked was

I want WatchDirectory to detect new Batch Scripts, *.cmd or *.bat, in a directory and automatically run them. I tried the Automatically Run Bat Files task, but it wants me to enter the name of the bat file to run. How can I do this?

The answer:

Yes, you need the "Run Bat Files" task, you just need to create a "static" batch file that will run the newly detected bat or cmd file. A simple RunTheNewScript.bat like this will do:

@echo off
rem the variable %WD_FILE% has the complete path to the newly detected script
Call "%WD_FILE%"
rem delete the script after it has run? Remove the "REM" on the next line
REM DEL "%WD_FILE%"

It is probably best to also Setup a Filter so this new task will only run when it detects a CMD or BAT file, see the picture below.

This is a low cost alternative to products such as Camellia Batch Job Server. Obviously, as a specialized program, Camellia BJS offers more/other functionality, but if all you need is to run dynamically created batch scripts automatically, you can do it with WatchDirectory.

No comments:

Post a Comment