Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm running Selenium using Maven through a .bat file from my desktop. Now, when I click for the first time, it runs. How can I avoid it to run when I click again? For example, it should show some message that an instance is already running.

This is my script:

cd C:\Automation\MavenHorizonAutomationFramework
mvn test 
share|improve this question

2 Answers 2

Use something like:

REM Test for lock file
IF EXIST lock.txt (
REM Do nothing
) ELSE (
REM Create lock file
ECHO > lock.txt

REM Call your applications here

REM Delete the lock file afterwards
DEL lock.txt
)

Since you've already written a batch file, I'll assume you're capable of integrating this into yours.

If you want to enhance it then you should write the process ID to the lock.txt file and, if it exists, test if the process number in the file also exists before assuming that it's running. That way if the process dies and the lock file isn't removed, you won't get it incorrectly thinking it's still running the next time the batch file is run.

share|improve this answer

You can write a lock file next to the script and remove it at the end of the script. When you start the script you should show the message if the file exists and exit. If the file does not exist it can continue running.

This is how yum and apt are doing it.

share|improve this answer
    
Thanks for the replay can you please provide me the script and belos is my script cd C:\Automation\MavenHorizonAutomationFramework mvn test –  ram Oct 17 '13 at 8:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.