|
Answer» Hi,
I have multiple batch files in a folder ,i want find out if batch A is running then batch B should not run and vice versa.
Any type of help will be appriciated.
regards,
GajananScripts and batch files have interpreters for execution and do nor run as processes. This SNIPPET shows a method for querying the window title but is not idiot proof. Depending how the batch file is launched will determine the actual window title and there are too many variations for a DEFINITIVE response.
Code: [Select]@echo off setlocal
for /f %%i in ('tasklist /nh /FI "WINDOWTITLE EQ Command Prompt - BatchA" ^| find /i "cmd.exe"') do ( if errorlevel 1 (echo BatchA is NOT running ) else (echo BatchA is Running) )
VBScript or Powershell would probably give you a better and more elegant solution.
Good luck.
It's too early for All Hallows Eve but something is about. When re-testing the code, it seems it might not work. Actually it screams, "IT WILL NOT WORK".
Try this more better code:
Code: [Select]@echo off setlocal
for /f %%i in ('tasklist /nh /fi "WINDOWTITLE eq Command Prompt - BatchA"') do ( echo %%i | find /i "cmd.exe" > nul if errorlevel 1 (echo BatchA is NOT running ) else echo BatchA is running) )
Thank you very much its working for. but if BatchA is running then it should exit from BatchB and viceversa. so it will be very helpful if you PROVIDE me that code. Quote from: Gajananpund on October 03, 2011, 11:02:35 PM so it will be very helpful if you provide me that code.
Surely you can work it out for yourself? Substitute:
if errorlevel 1...
for...
if errorlevel 0 goto eof
Quote from: Salmon Trout on October 04, 2011, 12:13:21 AMSurely you can work it out for yourself?
Sometimes.........it just doesn't make sense. Personally what I might do is make each batch script create a lock file after first checking for the existence of the other script's lock file and exiting if it is found. Or you could make it wait in a loop until the other script's lock file becomes non-existent. If it is not found, then the script creates its own lock file, performs it operations, then finally deletes its lock file.
e.g.
REM Batch A if exist batchB.lock exit echo abcde > batchA.lock bla bla bla bla bla bla del batchA.lock
REM Batch B if exist batchA.lock exit echo abcde > batchB.lock bla bla bla bla bla bla del batchB.lock
|