Reputation: 145
I have a simple batch script which is coping file from a folder and then move those files to a different folder. i set a up a task scheduler which working fine. but if another task run the cmd before previous task end, it will mixed up with the copy/move file job. is there anyway we can set the task scheduler that next task will run "only if previous task end"?
here is the screenshot i currently set https://i.sstatic.net/Gu056.png
Upvotes: 0
Views: 1335
Reputation:
As mentioned in the comments by Ikegami, You could use a lock file to test if the batch file is running and let the same process delete the lock file when the script is done. You have to be sure though that the script cannot exit unexpectedly.
Another way is to add the following to the top of your batch-file
@echo off
tasklist /FI "WINDOWTITLE eq my_job_run" | findstr /i "cmd.exe"
if not errorlevel 1 exit
title my_job_run
This will check if a process by the name of cmd.exe
exists with the window title of my_job_run
if it does, exit
and if it does not exist, continue and create the title, where the next run will detect it and not run the script again.
Upvotes: 1