Sign in to follow this  
Followers 0
xekon

Help? On Fatal Error, Launch different script.

15 posts in this topic

#1 ·  Posted (edited)

I have an autoit script named "script.exe" and when it gets a fatal error it stops running and opens a msgbox.

The script makes use of "#include <IE.au3>" the fatal errors only occur when I am having network/latency issues.

This is the reason I am not just debugging the script and would like to set it up to relaunch, just simpler.

How would I make it so that when it gets an error it does something like this:

sleep(1800000);wait 30 minutes
Run(@WorkingDir & "\relaunch.exe")

relaunch.exe is just a simple script to launch the original script:

while ProcessExists("script.exe") <> 0
ProcessClose("script.exe")
sleep(1000)
wend

Run(@WorkingDir & "\script.exe")
Edited by xekon

Share this post


Link to post
Share on other sites



xekon,

What is the "fatal error"?

Does the error terminate the script?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

and If you check the latency with

Ping()

?

$Delay = 2000

$Ping1 = Ping("www.youtube.com")
Sleep($Delay)
$Ping2 = Ping("www.google.com")
Sleep($Delay)
$Ping3 = Ping("drive.google.com")
Sleep($Delay)
$Latency = ($Ping1 + $Ping2 + $Ping3) / 3

If $Latency < 200 Then
;Your bugged func (part of the code) when latency is high
Else
;Refunc all func
EndIf

I've not tested it, test on your pc

But I think this may be a way

delay to avoid oscillation

Edited by GordonFreeman

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I will screenshot the error next time it does it.

currently I have windows scheduler set to run relaunch.exe every 3 hours which kills the existing script.exe and relaunches it. This works good for keeping it going, but sometimes it does not have a problem and there is no need to kill it and relaunch it, thats why I thought it would be cool to only relaunch it on error.

Edited by xekon

Share this post


Link to post
Share on other sites

Is it possible to post the code or send via PM?

And if you try to interact with the error message?. Is it fixed or differently each time?.

With the code can do more

Share this post


Link to post
Share on other sites

GordonFreeman,

Unless this is a rules violations it would be better to keep this in open forum then everyone gets a chance to learn something.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

The error was from an array variable that gets created from information fetched from the web. This information was fetched in a FOR loop and then used once fetched or after x amount of runs of the loop (1 to 500). What was happening is when i had network issues it would get all the way to 500 iterations of the loop and that variable would not get saved properly and then later in the script when I went to use the variable it complained because it was not of array type.

I changed the loop to

while 1

wend

and within the loop I use timerdif():

Global $last = TimerInit()
Func relaunch()
  $gdif = TimerDiff($last)
  If $gdif > 120000 Then;2mins
    Run(@WorkingDir & "\relaunch.exe")
  EndIf
EndFunc

while 1;mainloop
  $last = TimerInit()
  while 1;process loop
    relaunch()
    ;do stuff 1
    ;do stuff 2
    ;do stuff 3
    ;do stuff 4
    sleep(100)
  wend
  sleep(100)
wend

now if it times out for more than 2 minutes it will launch my relaunch.exe script.

if anyone uses any of this as an example, it is important to update $last = TimerInit() before any loops that get ran throughout your main loop, because it will eventually reach 2 minutes, My loops last for less than 20 seconds or so, so I am updating $last every 20 seconds, if it ever reaches 2 minutes than its a good chance my network has timed out.

So problem solved :)

Edited by xekon

Share this post


Link to post
Share on other sites

xekon,

Thank You,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

So I did solve one of my errors :) apparently I had more than one.

This one is out of my control:

Posted Image

so when my autoit script encounters an error, how can I make it so the script just closes, no error or popup or anything.

I found this post:

but I am not sure what is being suggested there or if that is what I am looking for.

So if anyone knows how make an autoit script exit silently on error instead of popping up an error box, please let me know.

Share this post


Link to post
Share on other sites

;http://www.autoitscript.com/forum/topic/126714-onautoiterrorregister-handle-autoit-critical-errors/

#include "OnAutoItErrorRegister.au3"

_OnAutoItErrorRegister("_RunScript")

Func _RunScript()
    Run("Path\to\my\script.exe")
EndFunc


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I think that it will be much better if you find a workaround for each error instead of just closing eyes and script :)

What was happening is when i had network issues it would get all the way to 500 iterations of the loop and that variable would not get saved properly and then later in the script when I went to use the variable it complained because it was not of array type.

Why do not you just add a check for variable type like this:

While IsArray($variable)=0
     ;add network connection checking here (maybe ping command or there is a special function in autoit) or sleeping interval
     ;call function to fill array from web once again, maybe need Dim $variable[size] in the begining
     getFromWeb()
WEnd
;process array

[Edited: changed loop to while, add network connection checking comment]

If I am right, last error appears because of some conditions were not met and variable $o_object don't get and IE object. If so, you can check this in If_Then_Else_EndIf (or other loop) too...

Edited by Eugenii

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Thanks JohnOne, that actually solves my problem.

I modified it slightly so it dont hammer the server im trying to connect to when its down:

_OnAutoItErrorRegister("_RunScript")


Func _RunScript()
TrayTip("","relaunching in 5minutes",999)
sleep(300000)
If @compiled then
Run(FileGetShortName(@ScriptFullPath))
Else
Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath))
EndIf
Exit
EndFunc

the only things I do that isue the IE.au3 are (One of these lines triggers the error when the site is down):

$sURL = "http://www.sitenamehere.php"
$oIE = _IECreate($sURL, 0, 0, 0)
$HWND = _IEPropertyGet($oIE, "hwnd")

WinSetState($HWND, "", @SW_MAXIMIZE)
_IEAction($oIE, "visible")
_IELoadWait($oIE)

$sText = _IEBodyReadText($oIE)

$oIE = _IEAttach ("sitename", "Embedded")
Edited by xekon

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Hm... Error caused by _IELoadWait($oIE) function call. And it seems to be normal, according to description "Browser scripting security restrictions may sometimes prevent _IELoadWait from guaranteeing that a page is fully loaded and can occasionally result in untrapped errors." However I tried your piece of code with my 64Kbps and loading of gmail inbox page and didn't get any error. But I got an error, when I closed IE manually, so these functions maybe are not ideal.

Some workarounds for this are described in _IELoadWait reference, and if you just want to get page content, maybe it will be better to download it from net (without loading IE)? Or it will not work fine with .php, which some content is generated by server on demand?

Edited by Eugenii

Share this post


Link to post
Share on other sites

well over the weeks I have watched it on and off, and it fails when the server I am trying to connect to becomes unresponsive and returns nothing. So there would be no downloading it from the net when the site is not responding, I could do a ping error checking, but i could see a rare instance where that could fail too, ping returns good and immediately after goes down (it would be rare)

so having it restart on error works good for me, because no matter what the script was in the middle of working on, it recovers its position on restart without issue.

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

I was still having problems with errors not being caught.

I have resolved my issues now though. I installed Firefox, adblock plus, mozrepl, went to the menu bar under tools>Mozrepl>Activate on startup.

and now I use FF.au3 instead of IE.au3: http://english.documentation.ff-au3.thorsten-willert.de/

script has been running rocksteady for 24, was not possible when I was using IE.au3

the LoadWait() in the FF package will return 0 instead of 1 when it fails, instead of crashing like IE did, so I do this now:

If _FFIsConnected() Then;make sure mozrepl is running and connectable
If _FFLoadWait() <> 1 Then;make sure that the page loads
_RunScript();if canot connect then relaunch
EndIf
EndIf

I attached a full example framework as well.

FF.au3 does need one fix (because of newer version of firefox), or _FFstart() loads two instances of firefox, atleast it did for me, try it first without this fix and if it launches two instances/tabs then apply this fix:

example.au3

Edited by xekon

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  
Followers 0