AutoHotkey Community

It is currently May 27th, 2012, 6:27 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: March 5th, 2011, 12:10 am 
Offline

Joined: July 20th, 2007, 5:49 am
Posts: 27
Hi,

I'd like to create a script that does something like so:

ScriptToRunProgram contains
Code:
   Wait until an instance of SomeProgram.exe is not running.
   Run "SomeProgram.exe"


Called this way: (Note: these scripts are called by another application one after the other and I don't have control over having it wait at this level)
    ScriptToRunProgram
    ScriptToRunProgram
    ScriptToRunProgram
    ...

I want the 2nd call to ScriptToRunProgram to wait until the 1st program is exited. I'd like the 3rd call to wait until the 2nd is done (however I'd take any order, as long as a single instance of the program is active at one time).

Any ideas on how to approach this to ensure that only one copy of SomeProgram.exe is loaded at a time? I can see issues with multiple scripts all testing at the same time and deciding to run. I tried a few things with Process that didn't work.

The actual application is for a source control app, executing a diff on an entire changelist, and only being presented with one file diff at a time instead of all trying to load at once. I'm pretty sure many years ago a co-worker wrote a batch file that did something like this, but that is lost to me.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2011, 12:18 am 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
You can use process, exist, or IfWinExist

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2011, 1:00 am 
Offline

Joined: July 20th, 2007, 5:49 am
Posts: 27
I mentioned I tried to get Process to work. I think there is overhead to starting up a new program that causes this to not work.

Code:
file1 = %1%
file2 = %2%

   keepGoing = 1;
   while (keepGoing = 1)
   {
      Process,Exist,WinMergeU.exe
      if (ErrorLevel)
      {
         MsgBox found WinMergeU
      }
      else
      {
         keepGoing = 0;
      }
   }

   Run "D:\Program Files (x86)\WinMerge\WinMergeU.exe" %file1% %file2%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2011, 1:05 am 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
I've made a few changes:
Code:
file1 = %1%
file2 = %2%
Process, WaitClose, WinMergeU.exe
Run "D:\Program Files (x86)\WinMerge\WinMergeU.exe" %file1% %file2%


Your while loop seemed really strange. I hope this helps.

Edit: typo in red

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Last edited by nimda on March 5th, 2011, 3:10 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2011, 2:12 am 
Offline

Joined: July 20th, 2007, 5:49 am
Posts: 27
This doesn't work. Multiple copies still execute. I'd already tried WaitClose, didn't try the name modification. Thanks for the suggestion though. Seems like I need something like a mutex, a simulated mutex on a temporary file, or some interprocess communication.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2011, 3:11 am 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
Really now. That's incredibly strange. I'm going to try it with notepad.exe and come back.

Edit: the following code is tested and runs only one instance of Notepad.exe at a time. I'm beginning to think there's a typo in your script, since this works fine
Code:
Loop{
Process, WaitClose, notepad.exe
Run notepad.exe
}
return

F6::ExitApp ; Panic Button in case Process WaitClose doesn't work / To be able to close Notepad easily

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2011, 4:49 pm 
Offline

Joined: July 20th, 2007, 5:49 am
Posts: 27
That works ok if you have a single instance of the script running. If you run multiple copies of the script the it will allow several copies of notepad to be in memory at once. Sometimes it will allow just one, it's just kind of random due to the nature of processing multiple threads.

The problem is that X numbers of the scripts can execute at once and I only want one of those to 'run' a notepad (winmerge).


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: hd0202 and 58 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group