Frage

Let's say I have multiple scheduled tasks running at different times, but all of which are running a common Windows batch file. This batch file in turn executes a Java program.

I would like my batch file to get the name of the scheduled task that's calling it, and pass its name to the program that my batch is executing. How can I do this?

War es hilfreich?

Lösung

Like Joey said there is no way to do it without getting help from outside.

You could create a separate instance of the batch for each task with an argument in each one specifying which task is assigned to run it. You could also create smaller batches like this one:

CALL mybatch.bat 1st_task

and that would pass the name of your first task into the batch as the %1 variable.

You could also have your batch figure it out based on the time that it was run using the %time% variable, but this would need some parsing I'm sure as you can't always guarantee it runs at the same time down to the second.

it might look something like this:

if '%time:~0,5%'=='10:30' set var=1st_task
if '%time:~0,5%'=='12:00' set var=2nd_task

and so on

(That last one assumes that your tasks only run at specified times during the day... and if for some reason they execute at a different time this won't work)

Andere Tipps

You could pass the name of the scheduled task as an argument to your batch file. You cannot figure it out from inside the batch without help from outside.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top