Jump to content
Sign in to follow this  

Premature script exit with RunWait and loops

Recommended Posts

I've been having trouble with a section of my script that waits for a process. While waiting, even though the process still exists, my script sometimes exits, particularly on computers where the process takes longer than other faster machines. I know this because my code logs its progress to a file as it runs. The section I've narrowed it down to is this:

Until Not ProcessExists("sfc.exe")

I initially was using RunWait to wait for the process to end, but that was sometimes failing on slower machines. So I tried a Do Until loop and then a While WEnd loop just to see if it made a difference.

I know I could have used Run and ProcessWaitClose but am trying to minimize its performance impact (only checking periodically instead of more frequently). I've watched my Autoit executable as it runs, and have noticed odd behavior regarding memory usage. It starts out with greater than 20mb of memory and as sfc.exe runs, my Autoit exe memory usage steadily drops until around 1mb, after which it unexpectedly quits. Here's a log to show how the memory usage drops as it runs:

          11:28 - 23,096 K
          11:29 - 20,468 K
          11:30 - 19,752 K
          11:31 - 17,912 K
          11:32 - 16,588 K
          11:33 - 11,724 K
          11:34 - 8,496 K
          11:35 - 6,764 K
          11:36 - 5,056 K
          11:37 - 3,688 K
          11:38 - 2,620 K
          11:39 - 1,916 K
          11:40 - 1,468 K
          11:41 - 1,228 K

I've worked around this issue by checking less frequently (increasing sleep). But it still seems to be a balancing game with the process check frequency or a race to try to make sure the script finishes before it runs too long and dumps out. But don't think I should have to do this if RunWait was working correctly in the first place.

I'm running Autoit v3.3.14.2, so thought I'd check the release notes for a newer version to see if this issue was addressed but didn't see anything related. Regardless, I upgraded to the current version v3.3.14.5, recompiled and am still experiencing the same behavior.

I've attached the full au3. The section in question is around lines 452 to 469.

Any advice is appreciated.


Edited by DrLarch

Share this post

Link to post
Share on other sites

You don't use RunWait in your WeeklyCleanup and you don't show the code neither in your snippet.   But I would guess that you do not check for any kind of error after the RunWait.  I suggest you fully test the exit code AND the @error after RunWait is completed.  You may learn what is causing the premature exit...

Share this post

Link to post
Share on other sites

As I mentioned in my first post, I did use RunWait initially. I'm checking for an error on that. That said, I tried compiling it as a console app and running it that way (and changed the _Log function to do ConsoleWrites instead). This way the memory isn't dropping and it's running fine which is weird. So now I'm having to chase it down a different rabbit hole. I'll update when I figure out more.

Share this post

Link to post
Share on other sites

Ok, I tried many different ways of pulling the exit code, both with RunWait and in a loop using If Not ProcessExists(ExitLoop) after just the Run function. Never caught any @error code, the script just quit.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...