Jump to content

Infinite Loop [RESOLVED]


Casey
 Share

Recommended Posts

All,

I have been working on a silent install script to do a chained install. Like many have posted on this kind of issue I have read the forum for the last couple of days, just about everything that I could find, and I am left still questioning if I have infinite loop possibility in my Do_Until statement. Since it is the first time I have used a loop I was hoping that someone could indulge me and confirm what I have done either does or doesn't have the potential.

The logic of a single install is:

check for existing versions > un-install old if present > Reboot if uninstall completed > run install if needed > if msiexec process exists after runwait has completed sleep for 2 minutes > if ProcessExists still then ProcessClose any open instances > what happens if it doesn't close? Infinite loop?

My concern is that from time to time I have seen msiexec still hanging around when the next install is launched so I wanted to prevent this yet I wanted to give it a few minutes to sort itself out. I have it set to log if this is used so that I can go back and review it to see if it is even needed after several trial runs.

What I present for your review is the piece about killing off the process(es) if still exist. It is slightly modified to use notepad and so that it actually does something since it was removed from the much to large script. It creates an install log at script directory, opens 20 instance of notepad and then closes them.

Any suggestions are welcome and thank you in advance for your time.

#include <GuiConstants.au3>
#include <File.au3>

If Not FileExists(@ScriptDir & "\Install.log") Then
    _FileCreate(@ScriptDir & "\Install.log")
EndIf

$InstallLog = @ScriptDir & "\Install.log" 

$i = 0 
While $i <= 19
    Run("Notepad.exe", "", @SW_MAXIMIZE)
    $i = $i + 1
WEnd

If ProcessExists("notepad.exe") Then
    $PROC_MSIExec_1 = MsgBox(1, "running Process Check", "Do you wish to terminate the running instance notepad.exe?")
    If $PROC_MSIExec_1 == 1 Then
                              ;---------------------------------------------------------------
        Do 
            $PID = ProcessClose("notepad.exe")
            ProcessWaitClose($PID)
            _FileWriteLog($InstallLog, "notepad.exe process terminated")
            $PROC_MSIExec_1a = ProcessExists("notepad.exe")
        Until $PROC_MSIExec_1a == 0
                              ;----------------------------------------------------------------
    EndIf
ElseIf $PROC_MSIExec_1 = 2 Then
    Exit
EndIf
Edited by Casey
Link to comment
Share on other sites

A couple things about your script:

- ProcessClose does not return anything:

$PID = ProcessClose("notepad.exe")
            ProcessWaitClose($PID)

is coded wrong - you won't have anything in your $PID variable and ProcessWaitClose($PID) will wait indefinitely.

To see what I'm talking about, add a messagebox to display $PID value.

$PID = ProcessClose("notepad.exe")
MsgBox(0, "$PID", "Your $PID variable is equal to "&$PID)
            ProcessWaitClose($PID)

To have it correct coded you will need in this particular case to identify every notepad window and to close these processes one by one. I'm affraid your example here (20 Notepad Instances) is not so close to your real need.

All you need there now is

ProcessWaitClose("notepad.exe")

Another thing: to create a file you don't need to use _FileCreate (and inclusion of File.au3 UDF) you just need to open the file in mode 2.

If Not FileExists(@ScriptDir & "\Install.log") Then
    $InstallLog = FileOpen(@ScriptDir & "\Install.log", 2) 
EndIf

will be a better replacement.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

  • 2 weeks later...

is coded wrong - you won't have anything in your $PID variable and ProcessWaitClose($PID) will wait indefinitely.

enaiman,

Sorry I didn't respond sooner. My employment sometimes means travel and taskings that take me out of the loop. In this case I was providing communication support for hurricane relief. Upon returning I then had to complete a teleport switch over and subsequent troubleshooting when a router suffered a corrupt IOS. Thank you very much for all the help here and on my previous posts.

After going back through the help file I see where I made the mistake above. Another good lesson was found in not using the first function that I come across in the help file. Not using _FileCreate makes perfect sense.

Thanks again for all the help.

V/r

Casey

Link to comment
Share on other sites

Hello,

It appears you have found your answer to your question.

Please take the time to edit your thread title with [RESOLVED] so others know that is it resolved.

You can do this by scrolling to the top of your thread, clicking EDIT and then Full Edit and adding: "[RESOLVED]"

to the front of your thread title.

Thanks for your cooperation.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...