I need to run two processes in parallel from a single batch file, which must be controlled from the Task Scheduler in Windows.
Following this answer https://stackoverflow.com/a/49051876/3834178 I created this batch file:
(
start "task1" cmd /C "command1"
start "task2" cmd /C "command2"
) | pause
and I created a Task in the Task Scheduler which runs that batch file.
Starting the Task, everything works: command1 and command2 are executed in parallel and run fine. The Task Scheduler shows "running".
However, if I try to stop the Task in the Task Scheduler, it shows "stopped" but command1 and command2 keep running, I can clearly see them in the Task Manager, and I have to manually stop them by killing them.
Question: how to improve the batch file so that it responds to the "stop" from Task Scheduler?
EDIT: some clarifications.
command1
andcommand2
start web servers and wait forever, i.e. are never ending programs unless stoppedpause
is real: not sure what it does here, but comes from the other question I linked above; afaik, it should wait for any output coming from the parentheses which never arrives by definition (start
suppress any output) and therefore lets the whole script to be running endlessy- the Task in Task Scheduler has no special configuration: it is set to run that batch on demand (no triggers) and anything else. I expect to start it with "play" and to stop it with "stop".