Jump to content

Auto re-run after exit


Recommended Posts

Welcome to AutoIt and the forum!

The clean solution is to solve the problem that lets our script stop.

Can you please post your code wrapped in [autoit][/autoit] tags? If its longer then a few statements could you please strip it down to a small reproducer script?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

hg2052,

I'm sure there is a way to determine whether or not the process has become unresponsive so you can kill it then reinvoke it or just set a timeout either way you'll have to do this from another process/script. If the function your using is just taking to long to respond but the process isn't hung then you should register and Adlib function to check for this.

Spoiler

censored.jpg

 

Link to comment
Share on other sites

If the cause for the hang is a web site that doesn't respond then I would suggest to use _IELoadWait with the timeout parameter set.

But first we need to see your code.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

;This is my file:

Global $Paused

HotKeySet("{ESC}", "Terminate")

#include <IE.au3>

#include<Array.au3>

#include<Table.au3>

#include<ExcelCOM_UDF.au3>

#include<Excel.au3>

$oIE = _IECreate('http://X1/x1')

$oProcessName="Excel.exe"

Local $file = FileOpen("C:X2.txt", 16384)

FileOpen("X3",1)

Local $oExcel = _ExcelBookNew(1)

Global $j=-2

While 1

HotKeySet("{ESC}", "Terminate")

$Timer = TimerInit()

Local $line = FileReadLine($file)

If StringFormat($line)<>"" Then

$adress='http://X1/' & StringFormat($line)

Local $oIE=_IECreate("http://X1")

Sleep(2000)

_IENavigate($oIE,$adress,1)

Sleep(10000)

$body = _IEBodyReadHTML($oIE)

Local $sHTML = _IEBodyReadHTML($oIE)

If StringInStr($body,'<table class="X4">',2) <> 0 Then

$j=$j+3

;MsgBox(0,"Table","Exists")

$vgt=VarGetType('<table class="X4">')

;MsgBox(0,"$vgt",$vgt)

$oTable = _IETableGetCollection($oIE)

Local $iNumTables = @extended

;MsgBox(0, "Table Info", "There are " & $iNumTables & " tables on the page")

$oTable = _IETableGetCollection ($oIE, $iNumTables-1) ; Get last table

$aTableData = _IETableWriteToArray ($oTable)

If $j>2 Then

_ArrayDelete($aTableData,0)

EndIf

;_ArrayDisplay($aTableData)

_ExcelWriteSheetFromArray($oExcel, $aTableData, $j, 1, 0, 0)

Sleep(1000)

;Local $oMarquee = _IEGetObjById($oIE, '<table class="X4">')

;FileWrite("X3.txt", StringFormat($aTableData))

Sleep(1000)

_IEQuit($oIE)

EndIf

_IEQuit($oIE)

EndIf

Wend

FileClose("X3.txt")

Func Terminate()

Exit 0

EndFunc

Link to comment
Share on other sites

Just a few hints:

  • Remove the HotKeySet from the While loop. Setting it once is sufficient
  • Remove the ExcelCOM_UDF.au3. You only call functions of Excel.au3
  • Remove "Local $oIE=_IECreate("http://X1")" from the While loop. You create the IE object at the start of the script - that's enough
  • Add "Opt("TrayIconDebug", 1) at the top of your script. If you move the mouse over the icon in the system tray you will see the statement where your script "hangs"
  • You can remove all "Sleep" statements because the script doesn't proceed before the previous statement hasn't finished

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

At what point in the script is it failing to respond? Also Using the Autoit tags (

[/Autoit]) really helps users here understand your code more easily:

[autoit]Global $Paused
HotKeySet("{ESC}", "Terminate")

#include <IE.au3>
#include<Array.au3>
#include<Table.au3>
#include<ExcelCOM_UDF.au3>
#include<Excel.au3>

$oIE = _IECreate('[url="http://X1/x1"]http://X1/x1[/url]')
$oProcessName="Excel.exe"


Local $file = FileOpen("C:\X2.txt", 16384)
FileOpen("X3",1)
Local $oExcel = _ExcelBookNew(1)
Global $j=-2
While 1
    HotKeySet("{ESC}", "Terminate")
    $Timer = TimerInit()
    Local $line = FileReadLine($file)
    If StringFormat($line)<>"" Then
        $adress='[url="http://X1/"]http://X1/[/url]' & StringFormat($line)
        Local $oIE=_IECreate("[url="http://X1"]http://X1"[/url])
        Sleep(2000)
        _IENavigate($oIE,$adress,1)
        Sleep(10000)
        $body = _IEBodyReadHTML($oIE)
        Local $sHTML = _IEBodyReadHTML($oIE)
        If StringInStr($body,'<table class="X4">',2) <> 0 Then
            $j=$j+3
            ;MsgBox(0,"Table","Exists")
            $vgt=VarGetType('<table class="X4">')
            ;MsgBox(0,"$vgt",$vgt)
            $oTable = _IETableGetCollection($oIE)
            Local $iNumTables = @extended
            ;MsgBox(0, "Table Info", "There are " & $iNumTables & " tables on the page")
            $oTable = _IETableGetCollection ($oIE, $iNumTables-1) ; Get last table
            $aTableData = _IETableWriteToArray ($oTable)

            If $j>2 Then
                _ArrayDelete($aTableData,0)
            EndIf
            ;_ArrayDisplay($aTableData)
            _ExcelWriteSheetFromArray($oExcel, $aTableData, $j, 1, 0, 0)

            Sleep(1000)
            ;Local $oMarquee = _IEGetObjById($oIE, '<table class="X4">')
            ;FileWrite("X3.txt", StringFormat($aTableData))
            Sleep(1000)
        _IEQuit($oIE)
        EndIf
    _IEQuit($oIE)
    EndIf
Wend

FileClose("X3.txt")

Func Terminate()
    Exit 0
EndFunc

Edited by MuchTex
Link to comment
Share on other sites

I posted in your second thread on this subject that I would like to keep on working in this thread because you've already posted some code here.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Water,

1.Sorry, I posted an answer for another of your answers.

2.Thank you, your suggestions are correct,except for the one cooncerning "Sleep":if I eliminate it after _IENavigate, the program hangs if the page takes a long time to download (I read somewhere that _IELoadWait works in fact only when you lod files from your computer)

Link to comment
Share on other sites

Seeker,

Thank you for using hte Autoit tags.

Concerning the point at which the script stops responding:I'm not sure what's provoking this,but I guess it's one of these:

-IEQuit:invalid data type repeating a certain number of times;

-server stopping to respond after a certain time (around 3 hours) or after having sent a certain amount of data (15-20 ko)

Link to comment
Share on other sites

_IENavigate is already waiting for the specified page to load (implied calling of _IELoadWait). So no Sleep should be necessary.

Unfortunately _IELoadWait sometimes returns even when the page hasn't been loaded completely.

Accoding to the help file for _IELoadWait:

"The most common causes of trouble are page redirects and cross-site scripting security restrictions associated with frames. Page re-writing techniques employed by some applications (e.g. Gmail) can also cause trouble here."

So I think the best way to make your script more reliable would be to check for the element you want to process to exist.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Water,

Maybe.

At anyrate, "Sleep" doesn't disturb me.

I think I'll:

-write some lines to exit the script after 120-150 min

-write another script to run this one at a certain interval after exit.

Maybe not elegant, but I hope efficient.

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