Checking to see if other scripts are running

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Semper
Junior Coder
Posts: 30
Joined: Mon Feb 25, 2008 3:28 pm

Checking to see if other scripts are running

Post by Semper » Sat Feb 15, 2014 1:28 pm

Hi,

i'm having difficulty solving this issue.
Let's say I have two scripts both using the time trigger to fire.

The script B (which runs later then script A) should not run at all if script A is still running.

I was trying to solve it with this http://www.mjtnet.com/blog/2006/09/15/r ... ncurrently
but it doesen't work because script A halts at any line of code it was on when the time for script B came up to run.
So script B is just waiting indefinitly for script A to finish, because it's in a loop code:

Code: Select all

SRT>WaitForIdle
  ReadIniFile>ctrl.ini,Share,RunStatus,IsIdle
  Wait>0.2
  If>IsIdle=ACTIVE,WaitForIdle
  EditIniFile>ctrl.ini,Share,RunStatus,ACTIVE
END>WaitForIdle
The Idle will never came up because script A which has to set it just pauses and waits for script B to finish.

So to sum it up, script B should wait for A to finish, and then run, regardles of the trigger it has.

I hope i wasn't too confusing. I would greatly appriciate if someone could point me in the right direction.

Thanks.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Sun Feb 16, 2014 6:09 am

I like dialogs. Perhaps I've said that before. In this case, dialogs can allow scripts to control one another.

Simply add a crude dialog at the start of Script A and add a test for that window name at the start of script B.

Script A:

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Caption = 'Script A'
end
EndDialog>Dialog1

//The rest of script A
Script B:

Code: Select all

Label>WaitingForScriptA
IfWindowOpen>Script A
  Wait>0.1
  Goto>WaitingForScriptA
EndIf

//The rest of script B
If Script A is Running Script B will not get past this loop until Script A finishes and the Script A window closes.

Semper
Junior Coder
Posts: 30
Joined: Mon Feb 25, 2008 3:28 pm

Post by Semper » Sun Feb 16, 2014 7:20 pm

Thanks JRL but I'm affraid the result is the same.

Script B just loops inside waiting for Script A to finish, but A stops at a line when B was triggered and waits for B to end.

I am testing this with Script A triggered to run on a certain time, and script B to start a minute later.
Script A:

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Caption = 'ScriptA'
end
EndDialog>Dialog1
Let>i=1
Wait>75
Let>i=2
Script B:

Code: Select all

Label>WaitingForScriptA
IfWindowOpen>ScriptA
  Wait>1
  Goto>WaitingForScriptA
EndIf
Let>a=1
A stops on line Wait>75 and B just loops every second indefinitly.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Feb 17, 2014 6:11 am

Semper,

I see what you mean. If you schedule two scripts and the second is scheduled to start before the first one completes, the first one stops while the second runs. So if the second one is written to wait until the first one completes there is deadlock.

You might try using the master script technique described here

Semper
Junior Coder
Posts: 30
Joined: Mon Feb 25, 2008 3:28 pm

Post by Semper » Mon Feb 17, 2014 7:32 am

Thanks again JRL.

When executing script with ExecuteFile, there is no log written, although that script have logging enabled. The log is a must on my system.

I actually can't belive MS itself don't have a simple method for checking whether any script is running. I don't think i'm asking much. Just to check and wait for a script to finish to be able to run another scheduled script.

Don't mind my tone, I'm a bit frustrated at this point :)

And I'm still left without a solution :(

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Feb 17, 2014 2:13 pm

You can create a log file by using the /logfile=logfilename parameter. Unfortunately ExecuteFile> fails when you try to pass parameters so you'll need to use RunProgram> instead. Something like the following should work for you. The %Command_Line% variable will contain the path and file name for msched.exe. The %script_dir% variable is the path to the default location of your scripts.

Code: Select all

Let>RP_Wait=0
RunProgram>%command_line% %script_dir%\Script A.scp /logfile=%script_dir%\Script A.log
RunProgram>%command_line% %script_dir%\Script B.scp /logfile=%script_dir%\Script B.log

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Mon Feb 17, 2014 4:33 pm

Just write to an INI file that both scripts have access to.

Script B just checks the entry every so often and if Script A has set the flag to 'Finished' (however you define that), then it runs, else loop again

The Read /Write INI files commands are solid and very easy to use.
What could be simpler?
Thanks,
Jerry

[email protected]

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Feb 17, 2014 4:59 pm

Jerry,
The problem here is that if you use Macro Scheduler's built in scheduling functions, Script A stops when Script B starts so Script A never gets to the point where it will update the INI file.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts