S
S
Sanya Hihi Haha2021-03-30 20:41:04
cmd/bat
Sanya Hihi Haha, 2021-03-30 20:41:04

How to exclude the possibility of running the same bat file?

Good day.
I have run.bat
With this content

start /d "C:\Users\valinor\Desktop\site\dist" main.exe --dir='D:\ttt'


I can have at least 100 such run.bat files, with the only difference that they are scattered in different folders, but inside they have the same command, the one shown above. (i.e. they access the same executable, but with different arguments)

Example
# папка1 по пути скажем C:\\data
start /d "C:\Users\valinor\Desktop\site\dist" main.exe --dir='D:\path1'

# папка2 по пути скажем C:\\data2
start /d "C:\Users\valinor\Desktop\site\dist" main.exe --dir='D:\path2'


Can I somehow prevent the launch of the same run.bat (roughly speaking, so that when I try to re-open the same run.bat from the same folder, either nothing happens while an instance of this batch file is still open, or I switch to already open window)? in order to exclude duplicates with the same arguments, the
PS executable was built using pyinstaller (and it is clear that the code is written in python, so in principle, if anyone has thoughts on how to do this in python code, I will be very grateful)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rPman, 2021-03-30
@ValarMayar

Do not make the restart control a batch file, it will be inconvenient, there is a topic where this was discussed there are examples
Better let the application itself do this, create a lock file (let the file name be in the parameters) with the pid of the process, when starting the application, it must check if the process exists with such pid as it is written in the file (if it exists), if there is - exit, if not - overwrite the file with your pid and continue working.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question