Skip to main content
Kevin Fegan's user avatar
Kevin Fegan's user avatar
Kevin Fegan's user avatar
Kevin Fegan
  • Member for 12 years
  • Last seen this week
  • Lombard, IL USA
awarded
revised
Set Variable in one line Batch
General cleanup and expansion of explaination.
Loading…
answered
Loading…
comment
How can I prevent to run same batch file twice to allow only one instance?
If there are multiple instances of the batch file running, PID5chars and PID4chars will only find one of them, and you will only know about that instance... Am I missing something? --- What I am trying to do is, upon running a batch file, check if there is an instance of that specific batch file already running. If there is another one running, just quit and let the previously running batch file continue to run. If there is no other one running, just continue to run.
comment
How can I prevent to run same batch file twice to allow only one instance?
(Part 2) --- It really seems like it should work, but I tried various settings for the "Title" command and "%PROCESS_NAME_TO_COUNT%" and almost got it working but never reliably/repeatedly. And, if 2 instances are started within a short time (some few seconds), "%PROCESS_COUNTER%" is always "=1" for both, so both continue to run.
comment
How can I prevent to run same batch file twice to allow only one instance?
1) You cover "process_count<2", "process_count=3", and "process_count>3"... What if "process_count=2" ? (Or will that never happen?). 2) You talk about using the "Title" command to set the "WINDOWTITLE", but you don't give an example of what to set the "Title" to, when (where in the code) "Title" should be set, and if/when "Title" should be reset to "Command Prompt". 3) In the "FOR" command you use %PROCESS_NAME_TO_COUNT%, but again, you don't set it before using it (it's UNDEFINED), you only "Reset" it to "NULL" after the "FOR" command completes. (Part 1/2: Continued-->)
awarded
awarded
awarded
awarded
awarded
awarded
awarded
awarded
awarded
Loading…
awarded
awarded
awarded
comment
Does %* in batch file mean all command line arguments?
@TWiStErRob - I'm sure you know it but to be clear... even with %* you need to use shift to access parameters beyond %9. The advantage of using %* is you can pass the entire ORIGINAL parameter list (including parameters that have been "shifted out") to an external batch or other program, or with a call :label %*, even if you don't know how many parameters are in the list (or if it's more than 9).
1
2 3 4 5
25