Looping Test - Works Sometimes

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

kriemer
Pro Scripter
Posts: 57
Joined: Fri Oct 30, 2009 2:59 pm

Looping Test - Works Sometimes

Post by kriemer » Tue Mar 22, 2011 2:09 pm

The script below is only a partial of the entire script; missing are another 6 test and run sections.

The "//Test If Files Exist" portion of the script works but randomly. I can run the script and all of the routines properly execute, files are saved in the proper locations but on completion the message box and log MAY indicate a file or 2 is missing. A second run, MIGHT complete properly or not.

The "//Test & Run VWR Scrapes" portion of the script NEVER fails, i.e., the test is always accurate as to the file having been created of not. If the file exists then that portion of the script does not execute, if the file does not exist then it does.

I suspect the problem is in the script, I just can't see where.

Any useful suggestions will be gratefully received.

//Variables
Let>loopcounter=-1
GetDate>vToday
Let>Missing1=FAILED On Loop 0 - Retry:%CRLF%
Let>Missing2=Files Missing:%CRLF%
Let>Path=Z:\VWR
Let>RuntimeHr=0.03
Let>RunTimeMin=RunTimeHr*60
Let>RunTimeSec=RunTimeMin*60
Let>LoopMax=1
Let>LoopTill=LoopMax+1
Let>LogFileLines=-100
Let>SizeLogFile=50000
Let>LogFile=%Path%\Log\VWR.Log

/*=============================================*/

//Delete VWR Output Files
DeleteFile>%Path%\Output\R*.*
DeleteFile>%Path%\Output\Y*.*
DeleteFile>%Path%\Output\Interactive*.*
Wait>10

//Trim VWR Log File to Last "n" Lines - Note: Tail.exe is saved in "C:\Windows\addins\" Directory
FileSize>%Path%\Log\VWR.Log,LogFileSize
If>LogFileSize>%SizeLogFile%
Let>RP_WAIT=1
Run>cmd.exe /c C:\Windows\addins\tail.exe %LogFileLines% "%Path%\Log\VWR.Log">"%Path%\Log\VWR TEMP.Log"
DeleteFile>%Path%\Log\VWR.Log
RenameFile>%Path%\Log\VWR TEMP.Log,%Path%\Log\VWR.Log
Let>RP_WAIT=0
endif

Repeat>loopcounter

//Close Message Window
IfWindowOpen>Macro Scheduler Message
CloseWindow>Macro Scheduler Message
endif>

//Test If Files Exist
IfFileExists>%Path%\Output\R_Estimates_a\R_Estimates_a_data_1.csv,,Skip
IfFileExists>%Path%\Output\R_Estimates_b\R_Estimates_b_data_1.csv,,Skip
IfFileExists>%Path%\Output\R_Estimates_c\R_Estimates_c_data_1.csv,,Skip

//Log and Exit Script If ALL Files Exist After "0" Try
if>loopcounter=0
Timestamp>LogFile,%vToday%, COMPLETED With No Errors - Yippie!!! %CRLF%
Exit>0
endif

//Log and Exit Script If ALL Files Exist After 1st -> "LoopMax" Retry
if>loopcounter>0
Timestamp>LogFile,%vToday%, COMPLETED With Errors!!! - Succeeded On Loop #%loopcounter% %CRLF%%Missing1%
Exit>0
endif

//Log and Exit Script If File(s) FAILED After "LoopMax" Retry
Label>Skip
if>loopcounter=LoopMax
Timestamp>LogFile,%vToday%, FAILED After %LoopMax% Retries!!! %CRLF%%Missing2%
MessageModal>FAILED After %LoopMax% Retries!!! %CRLF%%Missing2%
Exit>0
endif

Let>loopcounter=loopcounter+1
Let>Runcounter=loopcounter+1

//Time Calculation & Screen MessageBox - All Attempts
VBEval>DateAdd("s", %RunTimeSec%, now),LoopEndTime
Let>MSG_STAYONTOP=1
Message>Loop Run Time: %RunTimeHr% Hour(s) / %RunTimeMin% Min(s) %CRLF%Loop Completion: %LoopEndTime% %CRLF%Attempt No.: %Runcounter% of %LoopTill%

//Test & Run VWR Scrapes
IfFileExists>%Path%\Output\R_Estimates_a\R_Estimates_a_data_1.csv
//Do nothing
else
run>"C:\Program Files\VWR\RunProject.exe" "%Path%\Projects\R Estimates a.rip"
if>loopcounter>0
Let>Missing1=%Missing1%(%loopcounter%)R Estimates a %CRLF%
endif>
if>loopcounter=LoopMax
Let>Missing2=%Missing2%- R Estimates a %CRLF%
endif
endif

IfFileExists>%Path%\Output\R_Estimates_b\R_Estimates_b_data_1.csv
//Do nothing
else
run>"C:\Program Files\VWR\RunProject.exe" "%Path%\Projects\R Estimates b.rip"
if>loopcounter>0
Let>Missing1=%Missing1%(%loopcounter%)R Estimates b %CRLF%
endif
if>loopcounter=LoopMax
Let>Missing2=%Missing2%- R Estimates b %CRLF%
endif
endif

IfFileExists>%Path%\Output\R_Estimates_c\R_Estimates_c_data_1.csv
//Do nothing
else
run>"C:\Program Files\VWR\RunProject.exe" "%Path%\Projects\R Estimates c.rip"
if>loopcounter>0
Let>Missing1=%Missing1%(%loopcounter%)R Estimates c %CRLF%
endif>
if>loopcounter=LoopMax
Let>Missing2=%Missing2%- R Estimates c %CRLF%
endif
endif

//Pause Loop RunTimeSec

//"Kill" RunProject.exe
VBSTART
set wmi = getobject("winmgmts:")
sQuery = "select * from win32_process where name = 'RunProject.exe'"
set processes = wmi.execquery(sQuery)
for each process in processes
process.terminate
next
VBEND

//Loop Script "n" Times
Until>loopcounter=LoopTill

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

Post by JRL » Tue Mar 22, 2011 2:50 pm

Quick look at tyour script. Working backward from your tests eg,
IfFileExists>%Path%\Output\R_Estimates_a\R_Estimates_a_data_1.csv,,Skip

You're testing for the existance of csv files but I don't see anywhere prior that you are writing to or creating the csv files. So how are the tests valid?

kriemer
Pro Scripter
Posts: 57
Joined: Fri Oct 30, 2009 2:59 pm

Post by kriemer » Tue Mar 22, 2011 3:45 pm

First the files are deleted (from previous runs):
//Delete VWR Output Files
DeleteFile>%Path%\Output\R*.*
DeleteFile>%Path%\Output\Y*.*
DeleteFile>%Path%\Output\Interactive*.*
Wait>10

Later this section creates the files:
//Test & Run VWR Scrapes
IfFileExists>%Path%\Output\R_Estimates_a\R_Estimates_a_data_1.csv
//Do nothing
else
run>"C:\Program Files\VWR\RunProject.exe" "%Path%\Projects\R Estimates a.rip"
Thanks for taking the time to look.

k

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Mar 22, 2011 3:56 pm

After this:

run>"C:\Program Files\VWR\RunProject.exe" "%Path%\Projects\R Estimates a.rip"

What code do you have to ensure the script waits until this process is complete? Do you have RP_WAIT set etc?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

kriemer
Pro Scripter
Posts: 57
Joined: Fri Oct 30, 2009 2:59 pm

Post by kriemer » Tue Mar 22, 2011 4:06 pm

No I don't. I didn't think it necessary as the files are created (and the "Let>runtimehour=n" leaves a long time after programs end before the loop goes around to tests), but I will add and report back.

Thanks

k

kriemer
Pro Scripter
Posts: 57
Joined: Fri Oct 30, 2009 2:59 pm

Post by kriemer » Tue Mar 22, 2011 4:54 pm

I need all the "run>"C:\Program Files\VWR\RunProject.exe" "%Path%\Projects\XXX.rip" routines to run concurrently, then wait, then run the Test to complete.

"Let>RP_WAIT" waits for each section of the script to complete then allows the next run to start, etc. I tried putting "Let>RP_WAIT=1" before the "wait>RunTimeSec" line of code but "RP_WAIT" must be executed before the run statement not after.

So I don't think that "Let>RP_WAIT" can do what I want to do.

Thanks

k

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

Post by JRL » Tue Mar 22, 2011 5:16 pm

Maybe you can test for the process "RunProject.exe" to complete. If you are running MS version 12 you have the ProcessExists function. If not you will need to resort to testing using DOS. This of course assumes that the process is not running for some other reason. That it is only the three that you call using the Run> function.


Insert the following immediately after your Run sequences. Maybe around the "//Pause Loop RunTimeSec " line

Code: Select all

Label>TestForProcessComplete
  ProcessExists>RunProject.exe,vProc_var
  If>vProc_var=True
    Wait>0.1
    Goto>TestForProcessComplete
  EndIf

kriemer
Pro Scripter
Posts: 57
Joined: Fri Oct 30, 2009 2:59 pm

Post by kriemer » Tue Mar 22, 2011 6:37 pm

The "Label>TestForProcessComplete" works as advertised. Many Thanks

My problem is now getting "wait>RunTimeSec" to be able to timeout and restart the loop. Sometimes the individual RunProjects need to be restarted, they appear to enter some sort of stupid state which is why I have built the script to test and restart for n times.

Thanks again.

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

Post by JRL » Tue Mar 22, 2011 6:43 pm

When they enter their "stupid state" does the process stay open? If it does you might consider putting a counter in the "TestForProcessComplete" loop. If the counter reaches some outrageous number, you then deal wit ht errant process.

kriemer
Pro Scripter
Posts: 57
Joined: Fri Oct 30, 2009 2:59 pm

Post by kriemer » Tue Mar 22, 2011 6:56 pm

Yes the process does stay open.

It appears I am struggling against two competing requirements.

1 - The script to continue and reloop at the end of the "runtimesec" count
2- The script to wait for the processes to close before running the test portion of the script.

As I write this I think the answer is to put a simple "Wait>10" immediatly before the test portion of the script. When "runtimesec" completes it it allows the "Kill RunProject" portion of the script to shut down the projects and the test should be able to run uninterupted.

That is my theory at least. Any comments?

Thanks

k

kriemer
Pro Scripter
Posts: 57
Joined: Fri Oct 30, 2009 2:59 pm

Post by kriemer » Tue Mar 22, 2011 7:41 pm

I'm really confused. The processes all close, before the script loops around for the test phase. But the last loop of the script will more often than not incorrectly show some number of files as missing.

The good news is that it is not the logic of my script. I can be comfortable with that at least.

Thanks and still look forward to any thought/suggestions.

k

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

Post by JRL » Tue Mar 22, 2011 8:31 pm

How much has the script segment changed since your first posting?

kriemer
Pro Scripter
Posts: 57
Joined: Fri Oct 30, 2009 2:59 pm

Post by kriemer » Tue Mar 22, 2011 8:47 pm

I've only added a "WAIT>10" after the "Repeat>LoopCounter".

My logic is that after the script completes:
1 - "wait>RunTimeSec" -times out

starting

2 - //"Kill" RunProject.exe
VBSTART
set wmi = getobject("winmgmts:")
sQuery = "select * from win32_process where name = 'RunProject.exe'"
set processes = wmi.execquery(sQuery)
for each process in processes
process.terminate
next
VBEND

which, brings me back to:

3 - "Repeat>LoopCounter"

and back to

4 - "WAIT>10"
which should allow whatever remnants of RunProject are still in memory to close before running the "IfFileExists>XXX" tests.

To be clear, (and repetitive) it appears to me that it is only the final run of the first tests group (that go to the log file) that fail. If it was intermediate steps then I would be rerunning the the "run>" portions of the script and that does not appear to be happening.

I hope I am clear with this.

Many thanks for sticking with me.

k

kriemer
Pro Scripter
Posts: 57
Joined: Fri Oct 30, 2009 2:59 pm

Post by kriemer » Wed Mar 23, 2011 1:25 am

I have added the "TestForProcessComplete" script snippet right after the repeat loopcounter line. I no longer think it is necessary, but it is nice to be sure that RunProject is close, and it is way more efficient than a simple "Wait>n" statement.

I now have a new idea where my problem really lies. When my "LoopMax= value is set to 1 (i.e., 1 retry to complete) this value is the same as the "Missing1" value. It seems that this is where the script gets confused. If the "LoopMax" value is set to 2 or greater then the message window reports things properly.

Any ideas how to get around this one??

Many thanks in advance.

k

//Variables
Let>loopcounter=-1
GetDate>vToday
Let>Missing1=FAILED On Loop 0 - Retry:%CRLF%
Let>Missing2=Files Missing:%CRLF%
Let>Path=Z:\VWR
Let>RuntimeHr=0.03
Let>RunTimeMin=RunTimeHr*60
Let>RunTimeSec=RunTimeMin*60
Let>LoopMax=1
Let>LoopTill=LoopMax+1
Let>LogFileLines=-100
Let>SizeLogFile=50000
Let>LogFile=%Path%\Log\VWR.Log

/*=============================================*/

//Delete VWR Output Files
DeleteFile>%Path%\Output\R*.*
DeleteFile>%Path%\Output\Y*.*
DeleteFile>%Path%\Output\Interactive*.*
Wait>10

//Trim VWR Log File to Last "n" Lines - Note: Tail.exe is saved in "C:\Windows\addins\" Directory
FileSize>%Path%\Log\VWR.Log,LogFileSize
If>LogFileSize>%SizeLogFile%
Let>RP_WAIT=1
Run>cmd.exe /c C:\Windows\addins\tail.exe %LogFileLines% "%Path%\Log\VWR.Log">"%Path%\Log\VWR TEMP.Log"
DeleteFile>%Path%\Log\VWR.Log
RenameFile>%Path%\Log\VWR TEMP.Log,%Path%\Log\VWR.Log
Let>RP_WAIT=0
endif

Repeat>loopcounter

Label>TestForProcessComplete
ProcessExists>RunProject.exe,vProc_var
If>vProc_var=True
Wait>0.1
Goto>TestForProcessComplete
EndIf



//Close Message Window
IfWindowOpen>Macro Scheduler Message
CloseWindow>Macro Scheduler Message
endif>

//Test If Files Exist
IfFileExists>%Path%\Output\R_Estimates_a\R_Estimates_a_data_1.csv,,Skip
IfFileExists>%Path%\Output\R_Estimates_b\R_Estimates_b_data_1.csv,,Skip
IfFileExists>%Path%\Output\R_Estimates_c\R_Estimates_c_data_1.csv,,Skip

//Log and Exit Script If ALL Files Exist After "0" Try
if>loopcounter=0
Timestamp>LogFile,%vToday%, COMPLETED With No Errors - Yippie!!! %CRLF%
Exit>0
endif

//Log and Exit Script If ALL Files Exist After 1st -> "LoopMax" Retry
if>loopcounter>0
Timestamp>LogFile,%vToday%, COMPLETED With Errors!!! - Succeeded On Loop #%loopcounter% %CRLF%%Missing1%
Exit>0
endif

//Log and Exit Script If File(s) FAILED After "LoopMax" Retry
Label>Skip
if>loopcounter=LoopMax
Timestamp>LogFile,%vToday%, FAILED After %LoopMax% Retries!!! %CRLF%%Missing2%
MessageModal>FAILED After %LoopMax% Retries!!! %CRLF%%Missing2%
Exit>0
endif

Let>loopcounter=loopcounter+1
Let>Runcounter=loopcounter+1

//Time Calculation & Screen MessageBox - All Attempts
VBEval>DateAdd("s", %RunTimeSec%, now),LoopEndTime
Let>MSG_STAYONTOP=1
Message>Loop Run Time: %RunTimeHr% Hour(s) / %RunTimeMin% Min(s) %CRLF%Loop Completion: %LoopEndTime% %CRLF%Attempt No.: %Runcounter% of %LoopTill%

//Test & Run VWR Scrapes
IfFileExists>%Path%\Output\R_Estimates_a\R_Estimates_a_data_1.csv
//Do nothing
else
run>"C:\Program Files\VWR\RunProject.exe" "%Path%\Projects\R Estimates a.rip"
if>loopcounter>0
Let>Missing1=%Missing1%(%loopcounter%)R Estimates a %CRLF%
endif>
if>loopcounter=LoopMax
Let>Missing2=%Missing2%- R Estimates a %CRLF%
endif
endif

IfFileExists>%Path%\Output\R_Estimates_b\R_Estimates_b_data_1.csv
//Do nothing
else
run>"C:\Program Files\VWR\RunProject.exe" "%Path%\Projects\R Estimates b.rip"
if>loopcounter>0
Let>Missing1=%Missing1%(%loopcounter%)R Estimates b %CRLF%
endif
if>loopcounter=LoopMax
Let>Missing2=%Missing2%- R Estimates b %CRLF%
endif
endif

IfFileExists>%Path%\Output\R_Estimates_c\R_Estimates_c_data_1.csv
//Do nothing
else
run>"C:\Program Files\VWR\RunProject.exe" "%Path%\Projects\R Estimates c.rip"
if>loopcounter>0
Let>Missing1=%Missing1%(%loopcounter%)R Estimates c %CRLF%
endif>
if>loopcounter=LoopMax
Let>Missing2=%Missing2%- R Estimates c %CRLF%
endif
endif

//Pause Loop RunTimeSec

//"Kill" RunProject.exe
VBSTART
set wmi = getobject("winmgmts:")
sQuery = "select * from win32_process where name = 'RunProject.exe'"
set processes = wmi.execquery(sQuery)
for each process in processes
process.terminate
next
VBEND

//Loop Script "n" Times
Until>loopcounter=LoopTill

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

Post by JRL » Wed Mar 23, 2011 2:53 pm

OK...I just learned something. I was looking at your VB block as being a benign block of code because I've always thought that you NEED a VBRun or VBEval to execute a Visual Basic Script. But then I noticed that the format of the block would not lend itself to being run or evaled (no sub or function names) so I set up a test using notepad. Run the following and it will open notepad. Three seconds later it will close notepad. The VB block executes simply by existing in the script. I was unaware that could happen.

Code: Select all

Run>NotePad.exe
Wait>3

VBSTART
  set wmi = getobject("winmgmts:")
  sQuery = "select * from win32_process where name = 'NotePad.exe'"
  set processes = wmi.execquery(sQuery)
  for each process in processes
  process.terminate
  next
VBEND
So what I now see happening in your script is that you no more than start the "RunProject.exe" process than you are stopping it. That is to say. Though there are exceptions, in general, each line of code on my computer takes about six one hundred thousandths (0.00006) of a second to execute. This means that your script, if it was running on my computer, starts "RunProject.exe", and about seven ten thousandths (0.00072) of a second later kills it. Doesn't give the process much time to do anything.

I'm not sure why you want to kill the process rather than allow it complete.

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