Jump to content

stack overflow


Jochem
 Share

Recommended Posts

I have a problem with a stack overflow. I have a script running on all the computers on the network to see if a computer is running a program or not.

but after one and a half day it gets an error and than autoit closes the script to prevent a stack overflow, why is that?

#include <File.au3>
$gebruiker = @UserName
$os = @OSVersion
$comptername = @ComputerName
$logpath = "\\server\"
$logpath2 = "Log\"
$logpathadobe = "adobe\"
$iPID_1 = ("photoshop.exe")
$iPID_2 = ("indesign.exe")
$iPID_3 = ("illustrator.exe")
$iPID_4 = ("acrobat.exe")
Opt("TrayIconHide", 1)
Global Const $PROCESS_ALL_ACCESS = 0x1f0fff
_os()
Func _os()
    Select
        Case $os = "WIN_XP"
            If FileExists($logpath & $logpathadobe & $comptername & ".log") Then
                _checkadobe()
            Else
                _FileCreate($logpath & $logpathadobe & $comptername & ".log")
                _checkadobe()
            EndIf
        Case Else
            Exit
    EndSelect
EndFunc  ;==>_os
Func _checkadobe()
    If (ProcessExists($iPID_1)) Or (ProcessExists($iPID_2)) Or (ProcessExists($iPID_3)) Or (ProcessExists($iPID_4)) Then
        $log = FileOpen($logpath & $logpathadobe & $comptername & ".log", 1)
        FileWriteLine($log, "opened: " & @MDAY & "-" & @MON & " " & @HOUR & ":" & @MIN)
        FileClose($log)
        _checkadobeclose()
    Else
        _loop()
    EndIf
EndFunc  ;==>_checkadobe
Func _checkadobeclose()
    If (ProcessWaitClose($iPID_1, 0)) And (ProcessWaitClose($iPID_2, 1000)) And (ProcessWaitClose($iPID_3, 1000)) And (ProcessWaitClose($iPID_4, 1000)) Then
        $log = FileOpen($logpath & $logpathadobe & $comptername & ".log", 1)
        FileWriteLine($log, "closed: " & @MDAY & "-" & @MON & " " & @HOUR & ":" & @MIN)
        FileClose($log)
    EndIf
    _loop()
EndFunc  ;==>_checkadobeclose
Func _loop()
    Sleep(60000)
    _os()
EndFunc  ;==>_loop
Link to comment
Share on other sites

how many computers on the network.. whats the filesize of the log file.. when stack overflows..

What's the network topology..

Please provide all this information..

Also check this.

I would suggest that u write the logfile locally and then copy/update it.. on regular time intervals to the server.. that might help..

Edited by Manjish
[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

I suspect it's because _loop is called in a recursive loop (_loop calls os which calls loop and so on), in autoit you can only call a function recursively around 2000 times.

Try this instead:

#include <File.au3>
$gebruiker = @UserName
$os = @OSVersion
$comptername = @ComputerName
$logpath = "\\server\"
$logpath2 = "Log\"
$logpathadobe = "adobe\"
$iPID_1 = ("photoshop.exe")
$iPID_2 = ("indesign.exe")
$iPID_3 = ("illustrator.exe")
$iPID_4 = ("acrobat.exe")
Opt("TrayIconHide", 1)
Global Const $PROCESS_ALL_ACCESS = 0x1f0fff
While True
  Sleep(60000)
  _os()
WEnd

Func _os()
    Select
        Case $os = "WIN_XP"
            If FileExists($logpath & $logpathadobe & $comptername & ".log") Then
                _checkadobe()
            Else
                _FileCreate($logpath & $logpathadobe & $comptername & ".log")
                _checkadobe()
            EndIf
        Case Else
            Exit
    EndSelect
EndFunc;==>_os
Func _checkadobe()
    If (ProcessExists($iPID_1)) Or (ProcessExists($iPID_2)) Or (ProcessExists($iPID_3)) Or (ProcessExists($iPID_4)) Then
        $log = FileOpen($logpath & $logpathadobe & $comptername & ".log", 1)
        FileWriteLine($log, "opened: " & @MDAY & "-" & @MON & " " & @HOUR & ":" & @MIN)
        FileClose($log)
        _checkadobeclose()
    Else
        return
    EndIf
EndFunc;==>_checkadobe
Func _checkadobeclose()
    If (ProcessWaitClose($iPID_1, 0)) And (ProcessWaitClose($iPID_2, 1000)) And (ProcessWaitClose($iPID_3, 1000)) And (ProcessWaitClose($iPID_4, 1000)) Then
        $log = FileOpen($logpath & $logpathadobe & $comptername & ".log", 1)
        FileWriteLine($log, "closed: " & @MDAY & "-" & @MON & " " & @HOUR & ":" & @MIN)
        FileClose($log)
    EndIf
    return
EndFunc;==>_checkadobeclose

Not sure if your logic still holds, but it's the basic idea how to solve it.

:)

Edited by monoceres

Broken link? PM me and I'll send you the file!

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...